PowerShell Script: Move Users from OCS to Lync based on a Configuration Manager Report
I’m now working on a large Office 365 Pro Plus migration, and at the same time migrate users from OCS to Lync. This is a two-step process, but with PowerShell we can do this automatic.
Here is a script that moves the user automatically based on when the office 365 pro plus installs successfully.
I borrow some of the logic from Trond Egil Gjelsvik-Bakke
http://trogjels.wordpress.com/2012/09/20/enable-users-for-lync-via-ad-group-membership/
[code language=”powershell”]
#Sets variables
$xhttp = $nul
$stream = $nul
$username = "DOMAIN\USERNAME"
$password = "PASSWORD"
$url = ‘http://SERVER/SMSReporting_SITE/Report.asp?ReportID=110&StateName=Succeeded&AdvertID=CO12035A’
$destination = "C:\OCStoLyncMigration\Office Pro 365 Users Successfully installed $(get-date -f yyyy-MM-dd).csv"
$dateandtime = (Get-Date -format yyyy-MM-dd-HH:mm:ss)
#Create LogFile
$LogFile = "C:\OCStoLyncMigration\Enable-LyncUsers-Log-"+$(get-date -f yyyy-MM-dd)+".txt"
#Start XML
$xhttp = new-object -com msxml2.xmlhttp
$xhttp.open("Post",$url,$false,$username,$password)
$xhttp.setrequestheader("Content-Type","application/x-www-form-urlencoded")
#this sends the request to perform a CSV export
$xhttp.send("export=yes")
#Checks status
$xhttp.statustext
#Grabs the file in the buffer and save it to disk
$stream = new-object -com ADODB.Stream
$stream.open()
$stream.type = 1
#Connect the buffer to the downloaded file
$stream.write($xhttp.responsebody)
$stream.savetofile($destination,2)
$stream.close()
$stream = $nul
#Create variable Userlist from csv file
$Userlist=Import-csv $destination | Select-Object "user name"
#$LogTXT = " $dateandtime Processing Users…..`n"
#Out-File -FilePath $LogFile -InputObject $LogTXT -Append
Write-Host "$dateandtime Processing Users…..`n" -foregroundcolor Yellow -backgroundcolor Black
foreach ($u in $Userlist)
{
#Check if users upgraded still on OCS
$username = $u.’User Name’
$Domainuser="DOMAIN\$username"
$hp = get-csuser -filter {samAccountName -eq $username}
if($hp.HomeServer -eq ‘CN=LC Services,CN=Microsoft,CN=SERVER,CN=Pools,CN=RTC Service,CN=Microsoft,CN=System,DC=DOMAIN,DC=com’)
{
#Move user to Lync 2013
Move-CslegacyUser $Domainuser -Target SERVER.DOMAIN.com -Confirm:$false
$LogTXT = "$dateandtime Successfully moved $username to Lync 2013 On Premises"
Out-File -FilePath $LogFile -InputObject $LogTXT -Append
Write-Host $username "moved to Lync 2013 On Premises"
}
}
#Write Log
Out-File -FilePath $LogFile -InputObject $LogTXT -Append
[/code]