Possible way to Automating OnPrem to Cloud Skype users

Over the past couple weeks I have been trying to build a little automation for moving users from OnPrem Skype users to the cloud. Here is what I cam up with.

**you will need to install the Online modules for skype**

First need to create a hash of the password for the machine we want to run the scripts from.

Just a note, when running these, make sure you have CD to the working dir as these scripts assume the current dir the powershell is in.

This 1 liner creates the hash file that we will need in the next script.
Read-Host -Prompt "Enter your tenant password" -AsSecureString | ConvertFrom-SecureString | Out-File "cred.txt"


Here is the meat and spuds

#Time Stamp used for file naming
$DTStamp = get-date -f yyyy-MM-dd-hh-mm
#This uses a hash value of the password for the service user. This will allow us to run the script with out being asked
$AdminName = "ServiceUser@domain.com"
$Pass = Get-Content "cred.txt" | ConvertTo-SecureString
$credential= new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Pass
#Initialize session
$session = New-CsOnlineSession -Credential $credential -OverrideAdminDomain "TenantDomain.com"
Import-PSSession $session -AllowClobber
Set-ExecutionPolicy Unrestricted -force
#The Begaining of the inspection of users that will be moved
#Is the userlist file exist?
If ((test-path "userlist.txt") -eq $False) {
Send-MailMessage -from "Skype SkypeServers@domain.com" -to "Admin@domain.com"-subject "Skype Migrations: No File" -body "Looks like we dont have a file to work with" -smtpServer smtp.domain.com
#check to see if the users are enabled. This will output new file for working with.
ForEach ($UserToBeMigrated in (Get-Content userlist.txt)) {
get-csuser $UserToBeMigrated | Where-object {$_.Enabled -eq $False} | Select-object -expandProperty sipaddress | Out-File NotEnabledUsers.txt -append
get-csuser $UserToBeMigrated | Where-object {$_.Enabled -eq $True} | Select-object -expandProperty sipaddress | Out-File EnabledUsers.txt -append
#Start of moving users to the cloud with enabledusers.txt
ForEach ($UserToBeMigrated in (Get-Content EnabledUsers.txt)) {
Move-CsUser $UserToBeMigrated -Target sipfed.online.lync.com -Credential $credential -HostedMigrationOverrideUrl "https://.online.lync.com/HostedMigration/hostedmigrationservice.svc" -ProxyPool "<OnpremPool.domain.com" -Confirm:$False -verbose
# Lets give it a pause for any replication delays
Start-Sleep 60
#Lets verify the users where migrated
ForEach ($UserToBeMigrated in (Get-Content EnabledUsers.txt)) {
Get-CsUser $UserToBeMigrated | where-object {$_.hostingprovider -ne "sipfed.online.lync.com"} |Select-object -ExpandProperty Sipaddress | out-file LeftOvers.txt -Append
#If there were users that didnt move it will show up in the left overs file
If ((Get-Content "LeftOvers.txt") -eq $Null) {
ForEach ($UserToBeMigrated in (Get-Content EnabledUsers.txt)) {
get-csuser $UserToBeMigrated | select-object SipAddress, HostingProvider | Out-file completedList.txt -append
#If it passes lets send an email to the admin with some txt files to look through if he or she wants to
Send-MailMessage -from "Skype SkypeServers@domain.com" -to "Admin@domain.com" -subject "Move Complete" -body "Passed on first try. Logs attached" -Attachment "CompletedList.txt","NotEnabledUsers.txt" -smtpServer smtp.domain.com
rename-item -path completedList.txt -newName "CompletedList- $DTStamp.txt"
} else {
#If there is failure email and let the admin know
Send-MailMessage -from "Skype SkypeServers@domain.com" -to "admins@domain.com" -subject "Move Had Errors" -body "Looks like there was a failure. Trying in an hour, Logs attached" -smtpServer exapps.nml.com
#Here we could add another try to see if we can move the users again. This is a work in progress
#start-scheduledtask -taskname "ErrorRetry"
#Close them sessions
get-pssession | remove-pssession
#Clean Up
rename-item -path D:\temp\leftovers.txt -newName "LeftOvers- $DTStamp.txt"
rename-item -path D:\temp\userlist.txt -newName "UserList- $DTStamp.txt"
rename-item -path D:\temp\NotEnabledUsers.txt -newName "NotEnabledUsers- $DTStamp.txt"
rename-item -path D:\temp\EnabledUsers.txt -newName "EnabledUsers- $DTStamp.txt"


This script can now be added to a scheduled task so that every night it checks for the userlist.txt file to see new users need to be migrated.

I’ll be adding more to this as time goes on. Including what errors to expect.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s