Move or Enable Multiple User Accounts


Submitted by Scott Stubberfield and Nick Smith, Microsoft

 

Windows PowerShell makes it easy for you to enable a new user for Microsoft Lync Server 2010, and makes it just as easy for you to move a single user account from one Registrar pool to another. But what if you need to perform these user management tasks on a whole bunch of users, some of whom need to be enabled for Lync Server and some of whom need to have their accounts moved to a different Registrar pool? What do you do then?

 

Scott Stubberfield and Nick Smith have come up with one solution: you simply put all this information in a text file and then use a PowerShell script to read that text file and then take the appropriate action. The script they put together reads a comma-separated values file (a file containing user information), loops through the collection of users listed on that file and then does one of two things:

 

·         If the MoveOrEnable field for a user is marked as Move, the script uses the Move-CsUser cmdlet to move the user account from its current Registrar pool to a new Registrar pool (the Target field).

·         If the MoveOrEnable field for a user is marked as Enable, the script uses the Enable-CsUser cmdlet to enable the user account for Lync Server. The script assigns the user to the Registrar pool indicated by the Target field, and gives the user the SIP address listed in the SipUri field.

 

For example, suppose the first user listed in the .CSV file has these property values:

 

SipUri

sip:seeuser11@p10.ca

MoveOrEnable

Enable

Target

cspool.p10.ca

UPN

seeuser11@p10.local

 

Because MoveOrEnable is set to Enable, the script will enable the user for Lync Server, and will do so using the following command:

 

Enable-CsUser –Identity “seeuser11@p10.local” –RegistrarPool “cspool.p10.ca” –SipAddress “sip:seeuser11@p10.ca”

 

Nice, huh? And the best part is this: the script will take care of everything whether you have one user listed in the .CSV file or 100,000 users listed in the .CSV file.

 

Here’s what the code looks like:

 

param( [string] $importfile = $(Read-Host -prompt `
    “Please enter a file name”))

$importedusers = Import-CSV $importfile

 

$transcriptname = “MoveorEnableUsers” + `
    (Get-Date -format s).Replace(“:”,”-“) +”.txt”

Start-Transcript $transcriptname

 

foreach ($importeduser in $importedusers)

    {

        if ($importeduser.MoveorEnable -eq “Move”)

            {

                Move-CsUser $importeduser.SipUri -target `
                   $importeduser.Target -verbose

            }

        else

    {

        Enable-CsUser $importeduser.UPN -SipAddress `
            $importeduser.SipUri -RegistrarPool `
            $importeduser.Target -Verbose

    }

 

 

    }

Stop-Transcript

 

To make use of this script, copy the code to Notepad (or any other text editor), and then save the file using a .PS1 file extension (for example, C:ScriptsMoveOrEnableUsers.ps1). In addition, you must create a .CSV file similar to this, and save that file to your hard drive as well:

 

SipUri,MoveorEnable,Target,UPN

sip:seeuser11@p10.ca,Enable,”cspool.p10.ca”,seeuser11@p10.local

sip:seeuser12@p10.ca,Move,”cspool.p10.ca”,seeuser12@p10.local

sip:seeuser13@p10.ca,Enable,”cspool.p10.ca”,seeuser13@p10.local

sip:seeuser14@p10.ca,Enable,”cspool.p10.ca”,seeuser14@p10.local

sip:seeuser15@p10.ca,Enable,”cspool.p10.ca”,seeuser15@p10.local

sip:seeuser16@p10.ca,Enable,”cspool.p10.ca”,seeuser16@p10.local

sip:seeuser17@p10.ca,Enable,”cspool.p10.ca”,seeuser17@p10.local

sip:seeuser18@p10.ca,Move,”cspool.p10.ca”,seeuser18@p10.local

sip:seeuser19@p10.ca,Enable,”cspool.p10.ca”,seeuser19@p10.local

 

To run the script from within the Lync Server Management Shell, just type the full path to the .PS1 file and then press ENTER:

 

C:ScriptsMoveOrEnableUsers.ps1

 

When the script starts, it will prompt you to enter the location of the .CSV file. Type in the file path (e.g., C:ScriptsUsers.csv) and press ENTER; in turn, the script will read the data from the .CSV and, as requested, either move or enable each user listed in the file.

 

As an added bonus, the script also maintains a detailed log of everything it does. That log will be stored in the current working directory, and will have a file name based on the current date and time. For example:

 

MoveorEnableUsers2010-06-10T09-33-03.txt

Comments (9)
  1. CSPShell says:

    Hey atif, Can you give us some more details on what didn't work and what types of error messages you got? You can email us at cspshell@microsoft.com if that would be easier.

  2. ML49448 says:

    . When I run it it runs fine and imports the spreadsheet as designed and is successful in moving the users. The issue I have is, during the process it asks if you want to move the user and the choices are Y – yes, A – yes to all, N – no, and L – no to all. If I choose yes it works and moves to the next user and asks again. If I choose A for yes to all it moves the user and instead of moving on and doing the same to all the users it acts like I said yes and asks me again at each and every user. Does anyone there who is familiar with powershell know why the yes to all does not work as it should??

  3. CSPShell says:

    Hey Michael, Sorry we didn't get to this sooner, but it looks like you found your answer here: powershell.com/…/6783.aspx. As mentioned in that post, just set the -Confirm parameter to $False on the call to Move-CsUser.

  4. Bruce says:

    Hello,

    How do I create a CSV file of users to enable in this format;

    SipUri,MoveorEnable,Target,UPN

    sip:seeuser11@p10.ca,Enable,"cspool.p10.ca",seeuser11@p10.local

    sip:seeuser12@p10.ca,Enable,"cspool.p10.ca",seeuser12@p10.local

    I have around 160 people to enable at once. Is this generated from Lync 2010 Control panel? Any help would be greatly appreciated? Thank you.

Comments are closed.

Skip to main content