Running Commands against a list of users in a csv (O365)

Hi All, I posted this in the
O365 forum but was advised to post here instead.
I am trying to run some post deployment scripts on a list of users who have been migrated to O365. The list is from a csv.
Here is what I currently have, at the moment I am just trying to run Get Commands and then once I am happy I will when run the deployment Set commands.
So I have a csv file that loks like this:
UserPrincipleName
[email protected]
[email protected]
I have tried running the following, but the results I get show me results for every mailbox on our O365 organisation, not the 2 in my csv file.
Just so you know I can confirm  I am connected to the O365 Powershell session:
Import-CSV "C:\emails.csv" | ForEach-Object {Get-Mailbox | fl}
I have also tried this and I get the same results:
$list = Import-Csv "C:\emails.csv"
foreach($entry in $list) {
$User = $entry.User
Get-Mailbox -id $User
Any help would be greatly appreciated.

Hi All, I posted this in the
O365 forum but was advised to post here instead.
I am trying to run some post deployment scripts on a list of users who have been migrated to O365. The list is from a csv.
Here is what I currently have, at the moment I am just trying to run Get Commands and then once I am happy I will when run the deployment Set commands.
So I have a csv file that loks like this:
UserPrincipleName
[email protected]
[email protected]
I have tried running the following, but the results I get show me results for every mailbox on our O365 organisation, not the 2 in my csv file.
Just so you know I can confirm  I am connected to the O365 Powershell session:
Import-CSV "C:\emails.csv" | ForEach-Object {Get-Mailbox | fl}
I have also tried this and I get the same results:
$list = Import-Csv "C:\emails.csv"
foreach($entry in $list) {
$User = $entry.User
Get-Mailbox -id $User
Any help would be greatly appreciated.
Import-CSV
"C:\emails.csv" |
ForEach-Object
{Get-Mailbox $_| fl}

Similar Messages

  • Running MSOL commands against a list lof users from csv.

    Hi All, I was kindly helped here
    with a similar issue only the solution doesn't seem to work for the Get-MSolUser commands:
    What I am trying to achieve is to set the users -UsageLocation to GB and then to Set-MSolUserLicense to our Enterprise. So for example I have a list of UPN for our UK users in a csv:
    UserPrincipalName
    [email protected]
    [email protected]
    Here is what I have tried just to run a Get command first against the csv:
    Import-CSV "C:\emails.csv" | %{Get-MSolUser -identity $_.UserPrincipleName | fl}
    Which gives me this error:
    Import-CSV "C:\emails.csv" | %{Get-MSolUser -identity $_.UserPrincipleName | fl}
    +                                            
    ~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-MsolUser], ParameterBindingException
        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Online.Administration.Automation.GetUser
    I can confirm that if I run this command
    Get-MSolUser -All -UnlicensedUsersOnly | FT UserPrincipalName,DisplayName,IsLicensed,UsageLocation
    I do get a list of all users who are unlicensed.
    Any help on where I am going wrong would be greatly appreciated.

    Thanks Fred, that looks a lot better:
    Does this look correct to you?
    Import-CSV"C:\emails.csv"|%{Get-MSolUser-SearchString$_.UserPrincipleName
    |Set-MsolUser-UsageLocationGB
    Or do I need to define a ForEach -Object?

  • How to run commands upon system boot as user?

    How can I as a user run commands upon system boot? In Vixie's cron, one can use the @reboot syntax in a crontab, and the job is ran every time the cron daemon starts. Arch however, uses Dillon's cron which seems not support this feature.

    bwalk wrote:Hmm, does not work, because root owns init, so everything requires root. stb's version is valid, the -s parameter drops privileges to <USER>, spawns a shell and executes <COMMAND>. So, no security problem whatsoever.
    So there is nothing like @reboot in vixiecron?

  • Can ACS run commands at logon for specific users?

    I have a scenario where I'd like a command run at the time a user logs into the device. Can ACS do this on behalf of the user during the logon process?

    Sure. Bigip LTM, once authenticated, drops users into what is called a TMSH shell. This breaks rancid since rancid expects to be in a bash shell.
    You can access bash from TMSH via a command(run util bash). I'd like ACS to pass this command and run it the moment the rancid user logs in. That way subsoquent commands from rancid will work since he will at that point be at a bash prompt.
    Basically a logon script that runs commands for the user at the time the user logs in.

  • TS-Run Command Line-run as different user

    HI
    I needed to deploy one program which do not like SYSTEM account (do not installs). So I created TaskSequence with
    Run Command line and specified domain user which will be running this command.
    Is my domain users password safe or it will be provided in clear text in my network? Because this user must be Admin on local computer.

    Just to reinforce, the tasks use standard, core Windows APIs to impersonate the account and execute the command -- these APIs never send anything in clear text and if they did, then Windows has much bigger issues. It would actually take
    a huge amount of effort to not securely perform this operation.
    Jason | http://blog.configmgrftw.com

  • How to check a list of users against AD if they exist

    Hi Scripting Guys,
    I have a powershell script that allows me to query a list of users against AD, and if they exist, it will write their details into a new file.
    I want to adapt this script so that it will still do the same, but if the user does NOT exist anymore, write a line such as "<User-ID> does not exist in AD".
    Here's the code I have so far:
    Import-Module ActiveDirectory
    $UserList = get-content C:\temp\checkAD\Accounts.txt
    Foreach ($Item in $UserList) {
    Get-aduser -filter {samAccountName -eq $Item} | Out-File C:\temp\checkAD\existingAccounts.txt -encoding default -append
    Does anybody know how to achieve that?
    Thanks and best regards,
    Cap'

    Function LDAP_query{
    param
    [Parameter( Mandatory=$true )][String[]]$cID
    # change the DCs to your domain information
    $root = [ADSI]"GC://dc=$($cID[0]),dc=company,dc=com"
    $searcher = new-object System.DirectoryServices.DirectorySearcher($root)
    $searcher.filter = "(sAMAccountName=$($cID[1]))"
    #running LDAP query
    $cAcc = $searcher.findall()
    if($cAcc.Count -ne 0){
    return ($cAcc[0].Properties["samaccountname"][0])
    else{
    Write-Host -BackgroundColor Black -ForegroundColor Red "Error with account:" -NoNewline
    Write-Host " $($cID[0])\$($cID[1])"
    return ""
    The function is waiting for a string array: [domain][user id]
    Return the string of the User ID if valid, return an empty string if not a valid ID

  • Can't run command because user is in read-only mode.

    Hi
    I try to execute any sql statment i am getting this error.
    Can't run command because user is in read-only mode.

    user493528 wrote:
    I am having the same issue with Benthic when I do the With clause.
    I understand this is not related to Oracle but did anyone had issue related to this. I am getting the same error. Is it related to ODBC driver of how Benthic use to connect etc.,? I do not know.
    Thanks
    Gopihttp://www.benthicsoftware.com/support.html

  • Setting user permissions when running commands

    Here's a doosey,
    Looking to implement a system which will run "commands" being recieved from the network from a bunch of different users. I want the users to have different permissions depending on their username. I'm thinking the backing store as being an LDAP database. (easy update over the network, no using the policy editor, etc).
    Anyone got any advice, experience, existing products which do this? I"m looking at java.security.Profile and java.security.AccessController, java.security.ProtectionDomain and rolling my eyes. Kinda difficult.
    Am I barking up the wrong/right tree?
    Any ideas?
    Many thanks
    Keith

    I think I understand what you're saying, however i'm using the LDAP database to store the user's permissions (exactly like a policy file). So I"m not using LDAP to handle the authentication, just the data.
    It's the process of what you call "assigning the secuirty level" that I wanted to do...
    I think I've found what I'm looking for - JAAS. First I implent a java.security.Policy (in particular the getPermissions(ProtectionDomain domain) method). Then create my own java.security.Principal (containing the username) and associate that with a java.security.auth.Subject then use the Subject.doAs method.
    IN the command code then I do a AccessController.checkPermission(Permission ) method which will throw an exception if the permission is not found.
    I think this is it anyway.

  • Running commands as normal user

    Hi.
    Is it possible to do these things?
    Run audio without sudo...
    (Un)mount partitions without sudo...
    Poweroff, or reboot, without sudo...
    For instance, If I run:
    adduser myusername audio
    I'm told that the user already exists. I'm pretty sure nobody would design a system where everything you do needs to be sudo'ed. What am I doing wrong?

    I use pmount/pumount for mounting/unmounting as user.
    I've edited my sudoers file to give my user account access (only on this computer) to issue certain commands without a password. As far as I'm concerned, system commands such as shutdown should only be allowed to run as root. It's just a convenience for me not to have to type my password when using sudo.
    # less /etc/sudoers
    # sudoers file.
    # This file MUST be edited with the 'visudo' command as root.
    # Failure to use 'visudo' may result in syntax or file permission errors
    # that prevent sudo from running.
    # See the sudoers man page for the details on how to write a sudoers file.
    # Host alias specification
    # User alias specification
    # Cmnd alias specification
    # Defaults specification
    # Runas alias specification
    # User privilege specification
    root ALL=(ALL) ALL
    tom ALL=(ALL) ALL
    # Uncomment to allow people in group wheel to run all commands
    # %wheel ALL=(ALL) ALL
    # Same thing without a password
    # %wheel ALL=(ALL) NOPASSWD: ALL
    # Samples
    # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
    # %users localhost=/sbin/shutdown -h now
    tom kiwi = NOPASSWD: /sbin/halt
    tom kiwi = NOPASSWD: /sbin/reboot
    tom kiwi = NOPASSWD: /usr/bin/eject
    tom kiwi = NOPASSWD: /usr/sbin/pm-suspend
    tom kiwi = NOPASSWD: /home/tom/bin/backup
    tom kiwi = NOPASSWD: /etc/rc.d/httpd
    Which says: For the user tom on the computer kiwi allow him to run command /sbin/halt without a password.
    Last edited by BaconPie (2011-01-05 14:43:09)

  • Rc.local, run command as regular user?

    I want to run a command at startup that can't safely be run as root (and I don't want it to be anyway).  The only way I know of to execute a command at startup is rc.local, but that will run the command as root.  I know sudo can be used to run commands as other users.  If I use sudo to change what user the startup command is running as, will that be safe?  In other words, will that effectively make it as if it was being run by a regular user instead of root?  Or is there a better way of doing this?  Thanks.

    You can also put it in your .bashrc, so it will be executed every time you log in. For example, I have it set to mount my external disc if it's plugged but not mounted:
    if [[ -r /dev/disk/by-label/disco-externo && `mount | grep disco-externo | wc -l` -eq 0 ]]
    then
    sudo mount /dev/disk/by-label/disco-externo /mnt/disco-externo
    fi
    If you put the sudo away you can start any command as a regular user under certain circumstances.

  • [solved] hook to run commands when user logs in? (before bash profile)

    Is there any way to run commands when a user logs in but before the bash profile is sourced?
    For example, I have a user account with a home directory on /tmp. When the user logs in, the home directory might not exist so there will be no .bash_profile to source. I want to run a script to create the directory if necessary and copy some files into it. How can that be done?
    I thought of putting something in /etc/profile or /etc/profile.d/, but I would like to run something before the user's shell and environment become active.
    I can use /etc/rc.local to do what I want, but I would prefer a hook to ensure that everything is set right when the user logs in.
    Any ideas?
    *edit*
    Solution
    In my case, I found that I could write my own shell script and set it as a login shell. In the script, I can configure everything I need before launching the interactive shell, then clean up anything after it exits.
    Last edited by Xyne (2011-12-10 19:34:07)

    Thanks, dammannj. PAM could probably do what I need but I think I have found a simpler solution (see original post).

  • Made a bad change to login options under user preferences, changed from "List of users" to "Name and password". I shut the computer down, now I can't login in when I turn the computer back on.  What can I do to fix this problem?

    Have Migrated data from IMAC to Macbook twice.  Because I had too many admin ids under user and accounts preferences, I was trying not to delete the extras but that they wouldn't all show at login time.  Under Login Options, I clicked out  "List of Users" and clicked in "Name and password".  Can't remember whether I did anything else.  I shut down the computer and turned it back on to test the change.  I get a dark grey screen with all my admin ids in circled pictures plus one for guest, but doesn't let me do anything with any of the admin ids.  I clicked on any one and nothing happens.  IF i click on the guest circle, it gives me a message that the computer will restart with only Safari allowed.
    Since I haven't been able to connect my macbook to my IMac so I can login to the macbook through the Imac, I can't get to my macbook.  There must be a way to fix this problem.  I expected to see places to enter name and password but nothing is allowed to enter.  Please help!

    First thing I would do would be to boot in to Lion Recovery (Command+R on boot) and run Disk Utility, both disk and permissions repair.

  • Using java to run command line as %username%

    Hi all,
    can any one help with this?
    I'm trying to run a command line from a database as %username% in Windows. So far I have the following script, courtesy of Frank Naude to build a java class that is published within a plsql procedure. A command line can then be passed to it.
    rem -----------------------------------------------------------------------
    rem Filename: oscmd.sql
    rem Purpose: Execute operating system commands from PL/SQL
    rem Notes: Specify full paths to commands, for example,
    rem specify /usr/bin/ps instead of ps.
    rem Date: 09-Apr-2005
    rem Author: Frank Naude, Oracle FAQ
    rem -----------------------------------------------------------------------
    rem -----------------------------------------------------------------------
    rem Grant Java Access to user USER1
    rem -----------------------------------------------------------------------
    conn sys/password@database as sysdba
    EXEC dbms_java.grant_permission('USER1', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC dbms_java.grant_permission('USER1', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    EXEC dbms_java.grant_permission('USER1', 'SYS:java.io.FilePermission', '/bin/sh', 'execute');
    EXEC dbms_java.grant_permission( 'USER1', 'SYS:java.io.FilePermission','C:\WINDOWS\system32\cmd.exe', 'execute' );
    rem -----------------------------------------------------------------------
    rem Create Java class to execute OS commands...
    rem -----------------------------------------------------------------------
    conn user1/password@database
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    finalCommand = new String[4];
    finalCommand[0] = "C:\\WINDOWS\\system32\\cmd.exe";
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    // Execute the command...
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    // Capture output from STDOUT...
    BufferedReader br_in = null;
    try {
    br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("stdout: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_in.close();
    } catch (IOException ioe) {
    System.out.println("Error printing process output.");
    ioe.printStackTrace();
    } finally {
    try {
    br_in.close();
    } catch (Exception ex) {}
    // Capture output from STDERR...
    BufferedReader br_err = null;
    try {
    br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("stderr: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_err.close();
    } catch (IOException ioe) {
    System.out.println("Error printing execution errors.");
    ioe.printStackTrace();
    } finally {
    try {
    br_err.close();
    } catch (Exception ex) {}
    catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage());
    show errors
    rem -----------------------------------------------------------------------
    rem Publish the Java call to PL/SQL...
    rem -----------------------------------------------------------------------
    CREATE OR REPLACE PROCEDURE host(p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    show errors
    rem -----------------------------------------------------------------------
    rem Let's test it
    rem -----------------------------------------------------------------------
    exec host('notepad');
    The trouble is although this script works great for commands that can be run is the 'background' as SYSTEM is I want to pass a command to actually open something e.g. notepad in the above example nothing seems to happen. As far as I can make out the command line is running but not as %username% so it's not running notepad.exe in the foreground.
    I'm happy to clarify more if necessary.
    Can anyone help with this?
    Cheers
    Yog

    Bill,
    Thank you for the quick answer. I believe you are right in your assumption.
    I have been searching but found nothing so far.
    I need to be able to run this line "wmic
    Product where name='XXX XXX XXX' call uninstall" 
    in an elevated command prompt to uninstall the program.
    I was looking for a VB script or PowerShell to execute it remotely on non domain roaming PCs.
    Th3e command can be run remotely against stand-alone workstations but you must supply credentials.  Post in the platform forum for you version of Windows for help in using the WMIC utility.  WMIC /? will give you all of the command options fro
    remote execution.  UAC only affects local systems.  You cannot use WMIC to remote back to the local system. WMIC does not allow impersonation to the local system.
    Most installers will not automatically allow an unattended uninstall.  If there is any dialog at all the uninstall will fail and can hang.
    I recommend contacting the vendor of the application to get more information.
    In all cases you cannot bypass UAC as Bill has noted.  I am only noting that, sometimes, in a workgroup, you can use WMIC to remotely uninstall an application.
    ¯\_(ツ)_/¯

  • Help me to fix the error while running DBMaintain Against the Database Schema in ASE.

    Hi All,
    I am trying to install sybase mobiliser platform 5.1 SP 03.I am  referring the following guide
    http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01871.0513/pdf/Mobiliser_Platform_Installation_Guide_5.1…
    Now I have configured the ASE database server with default settings and now it is running fine.
    Now my concerns are as follows:
    1) I have executed the database schema (mobr5): 001_MONEY_drop_and_create_user.DDL with the help of linux command
    isql -Usa -SASE1 -Phello@123 -i/opt/sybase/db/sql/001_MONEY_drop_and_create_user.DDL -o/opt/sybase/ASE-15_0/install/ASE1.log
    How do I check the created database schema and user with default name 'mobr5'?
    2) While running DBMaintain Against the Database Schema, I have followed the steps mentioned in the guide and made the following changes in the file dbmaintain.properties.ase
    database.driverClassName=com.sybase.jdbc4.jdbc.SybDriver
    database.url=jdbc:sybase:Tds:ASE1:5000/mobr5
    database.userName=mobr5
    database.schemaNames=mobr5
    database.password=paybox
    #Must be set if the driver is not packaged inside the scriptarchive or is present on the classpath
    #e.g. /path/to/driver.jar
    #database.driverLocation=/path/to/jconnect.jar
    database.driverLocation=/opt/sybase/db/sql/com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase.jar
    database.driverLocation=/opt/sybase/db/sql/com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase-vanilla.jar
    When I execute the script archives ,
    java –jar /opt/sybase/db/sql/com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase-driverless.jar -c /opt/sybase/db/sql/dbmaintain.properties.ase
    java –jar com.sybase365.mobiliser.vanilla.standalone-5.1.3.RELEASE-scriptarchive-ase-vanilla-driverless.jar -c dbmaintain.properties.ase
    I get the following error:
    So please help me to resolve the issues.

    Hi All,
    Issue is resolved and database has been updated successfully..
    Error was in database .url field of dbmaintain.properties.ase file.
    I have changed the database.url field  from database.url=jdbc:sybase:Tds:ASE1:5000/mobr5
    to  database.url=jdbc:sybase:Tds:<Private IP of Linux instance>:5000/mobr5
    Note:- I am installing mobiliser platform on AWS cloud.So I have made use of Private IP address of AWS Linux instance.

  • Extract list of users in OBIEE 11g

    Can someone please tell me what is the way to extract the list of users using OBIEE 11g with their roles and permissions.
    Thanks in advance.

    Check this script
    '1: Make an UDML export of the RPD using nqgenudml.exe
    '2: Change the filename/location in this script
    '3: Run the script from the command line cscript Read_Usergroups.VBS > users.txt
    '4: Put the export in a XLS Pivot table
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'point this to your UDML EXPORT
    Set objFile = objFSO.OpenTextFile("E:\usergroup.txt", ForReading)
    Const ForReading = 1
    Dim arrFileLines()
    dim strRLine
    dim strTemp1
    dim strTemp2
    dim strTemp3
    dim intRoles
    intRoles = 0
    i = 0
    WScript.Echo "USER_NAME;FULL_NAME;ROLE;COUNT"
    Do Until objFile.AtEndOfStream
    strRline = objFile.ReadLine
    if left(strRline,12) = "DECLARE USER" then Redim Preserve arrFileLines(i)
    strTemp1 = MID(strRLine ,15 , 50)
    strTemp1 = MID(strTemp1 ,1 , instr(strTemp1, """")-1)
    IF instr(strRline,"}" ) >0 THEN
    strTemp2 = MID(strRLine , instr(strRline,"{")+ 1, (instr(strRline,"}") - (instr(strRline,"{")+ 1)))
    ELSE
    strTemp2 = ""
    END IF
    arrFileLines(i) = strTemp1 &";" & strtemp2
    intRoles = 1
    i = i + 1
    end if
    if intRoles >= 1 then
    if instr(strRline,"HAS ROLES (" ) >0 then
    intRoles =2
    end if
    if intRoles =2 and instr(strRline,"HAS ROLES (" ) =0 then
    strTemp3 = MID(strRline,instr(strRline, """")+1,50)
    strTemp3 = MID(strTemp3,1,instr(strTemp3, """")-1)
    WScript.Echo arrFileLines(i-1) &";" & strTemp3 &";1"
    end if
    if intRoles =2 and instr(strRline,")" ) >0 then intRoles = 0
    end if
    end ifLoop
    objFile.Close
    Source : Srinivasan Software Solutions Pvt.Ltd.: [OBIEE 11g] OBIEE Get All Users And Roles From RPD

Maybe you are looking for