Skip to content

Instantly share code, notes, and snippets.

@tathamoddie
Created October 3, 2016 13:52
Show Gist options
  • Save tathamoddie/77fc86bc69dc34d17f6023a14844cb5f to your computer and use it in GitHub Desktop.
Save tathamoddie/77fc86bc69dc34d17f6023a14844cb5f to your computer and use it in GitHub Desktop.
Skype for Business: migrate only active ACP users to the Microsoft Bridge
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[Parameter(Mandatory=$True)]
[PSCredential]$Credential,
[int]$BatchSize = 200
)
Import-Module 'C:\Program Files\Common Files\Skype for Business Online\Modules\SkypeOnlineConnector'
$skypeSession = New-CsOnlineSession -Credential $cred
Import-PSSession $skypeSession -AllowClobber | Out-Null
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $exchangeSession -AllowClobber | Out-Null
function Count-RecentlyOrganizedDialInConferences($upn) {
$dawn = [DateTime]::Now.AddMonths(-3)
$activities = $null
$reportAttemptsLeft = 50
while ($activities -eq $null -and $reportAttemptsLeft -gt 0)
{
$errorCountBefore = $Error.Count
# This cmdlet doesn't seem to actually fire a terminating error with Stop
$activities = Get-CsUserActivitiesReport -UserName $upn -StartDate $dawn -ErrorAction Stop
if ($Error.Count -eq $errorCountBefore)
{
break;
}
else
{
# The datamart is really flakey, but seems to warm up
Start-Sleep -Seconds 0.5
$reportAttemptsLeft = $reportAttemptsLeft--
}
}
$stats = $activities | measure -Sum -Property TotalOrganizedDialinConferences
if ($stats.Count -eq 0) {
# Inconclusive
$null
}
else {
$stats.Sum
}
}
Write-Verbose 'Find all ACP users who are eligible for the Microsoft Bridge'
$peopleUsingAnAcp = Get-CSOnlineUser |
? {
$_.OnlineDialinConferencingPolicy -eq 'ServiceAllowed' -and
$_.AcpInfo -ne $null -and
([xml]$_.AcpInfo).acpInformation.name -ne 'Microsoft'
} |
select -ExpandProperty UserPrincipalName -First $BatchSize
Write-Verbose 'Find recent ACP usage'
$count = $peopleUsingAnAcp.Count
$done = 0
$peopleAndStats = $peopleUsingAnAcp |
% {
$upn = $_;
Write-Progress -Activity 'Searching dial-in conferencing history (expect transient data mart failures)' -Status $upn -PercentComplete (100 * $done / $count)
$confCount = Count-RecentlyOrganizedDialInConferences $upn
New-Object PSObject -Property @{
UserPrincipalName = $upn
DialInStatus = &{
if ($confCount -eq $null) { 'Unknown' }
elseif ($confCount -gt 0) { 'Active' }
elseif ($confCount -le 0) { 'Inactive' }
}
RecentlyOrganizedDialInConferences = $confCount
}
$done ++
}
Write-Progress -Activity 'Searching dial-in conferencing history' -Status 'Done' -Completed
$peopleAndStats | sort -Property DialInStatus, UserPrincipalName | ft
Write-Verbose 'Migrate active ACP users to Microsoft Bridge'
$migrationCandidates = $peopleAndStats |
? { $_.DialInStatus -eq 'Active' }
$count = $migrationCandidates.Count
$done = 0
$migrationCandidates | % {
$entry = $migrationCandidates[$done]
Write-Progress -Activity 'Enabling Microsoft Bridge' -Status $entry.UserPrincipalName -PercentComplete (100 * $done / $count)
if ($PSCmdlet.ShouldProcess($entry.UserPrincipalName, 'Enable-CsOnlineDialInConferencingUser')) {
Enable-CsOnlineDialInConferencingUser -Identity $entry.UserPrincipalName -ReplaceProvider
}
$done ++
}
Write-Progress -Activity 'Enabling Microsoft Bridge' -Status 'Done' -Completed
Disconnect-PSSession $exchangeSession -WhatIf:$false
Disconnect-PSSession $skypeSession -WhatIf:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment