Skype4Business Custom Commands. Avvulous Jun 8th, 2016 ( edited ) 262 Never 262Never

Not a member of Pastebin yet? Sign Up , it unlocks many cool features!

rawdownloadcloneembedreportprint PowerShell 7.30 KB Function Get - PoolFQDN { #see if we can grab the sip address from registry, to get the domain. otherwise prompt for it. $Matches = $null Try { $Try16 = ( Get-ItemProperty "HKCU:\Software\Microsoft\Office\16.0\Lync" -ErrorAction SilentlyContinue ) .ServerSipURI -match ".+@(.+)" IF ( ! $Try16 ) { $Try15 = ( Get-ItemProperty "HKCU:\Software\Microsoft\Office\15.0\Lync" -ErrorAction SilentlyContinue ) .ServerSipURI -match ".+@(.+)" } } Catch { } If ( $Matches ) { $DomainName = $Matches [ 1 ] } Else { $DomainName = Read-Host "Please enter your domain name (e.g. contoso.com)" } #Connect to the LyncDiscoverInternal address for the domain name specified, and retrieves the pool FQDN. $Matches = $null Try { ( Invoke - WebRequest "https://LyncDiscoverinternal.$($DomainName)" ) .Content -Match ".+http(?:s?)://(.+?)/.+" > $null } Catch { } If ( $Matches ) { $PoolFQDN = $Matches [ 1 ] } Else { $PoolFQDN = Read-Host "Could not discover pool FQDN, Please enter it manually" } return $poolFQDN } function Connect - LyncSession { param ( [ string ] $PoolFQDN , [ switch ] $Insecure , $Cred ) #if not specifed, get the pool FQDN automatically (if possible) If ( ! $PoolFQDN ) { $PoolFQDN = Get - PoolFQDN } #attempt to connect to the lync pool, display errors if it fails. Try { $cred .Password.GetType ( ) > $null } Catch { $cred = Get-Credential -Message "Admin credentials for $($PoolFQDN):" } Try { $cred .Password.GetType ( ) > $null $sessionOption = New - PSSessionOption - SkipRevocationCheck If ( $Insecure ) { $ConnURI = "http://$($PoolFQDN)/OcsPowershell" } Else { $ConnURI = "https://$($PoolFQDN)/OcsPowershell" } $session = New - PSSession - ConnectionURI $ConnURI -Credential $cred - SessionOption $sessionOption -ErrorAction Stop Import - Module ( Import - PsSession $session - AllowClobber ) - Global } Catch [ Exception ] { If ( $_ .Exception.Message.ToString ( ) -like "*null-valued expression*" ) { Write-Host "Please enter credentials." -ForegroundColor Red } Else { Write-Host "Error Connecting to Lync Server : `r `n " -NoNewLine ; Write-Host "$($_.Exception.Message)" -ForegroundColor Red } } } function Get - CsAgentGroupMembership { Param ( [ Parameter ( Mandatory = $true ) ] [ string ] $UserID , [ switch ] $ReturnGrid , [ switch ] $ReturnInfo ) #get user $Usr = Get - CsUser $UserID -ErrorAction SilentlyContinue #loop through all groups, check if the user is in any of them. #three return types, default only group names, -ReturnGrid for gridview of all info, -ReturnInfo for array of group objects. If ( $Usr -ne $null ) { $Groups = @ ( ) Get - CsRgsAgentGroup | Where-Object { $_ .AgentsByUri -contains $Usr .SipAddress.ToLowerInvariant ( ) } | % { $Groups += $_ } If ( $ReturnGrid ) { $Groups | Out - GridView -Title "Rgs Group Membership : $($Usr.DisplayName)" } ElseIf ( $ReturnInfo ) { return $Groups } Else { Return $Groups .Name } } Else { Write-Error "Could not find '$($UserID)'" } } Function Get - CsAssignedURIs { # Get-CsAssignedURIs –LineURI “1234” –PartialMatches # Will return any numbers with ‘1234’ anywhere in them. # Get-CsAssignedURIs –DuplicateLines –IgnoreExt # Will return all duplicate numbers, ignoring any extensions. # Get-CsAssignedURIs –ReturnNumbers (Or nothing specified) # Will return a big list of all numbers assigned in lync. # # -PartialMatches or –IgnoreExt can be excluded, they will return only exact matches (incl. tel:), or check extensions respectively. # # You can also use the –ReturnAsObject parameter with any of these commands, and output it to a file etc.: # Get-CsAssignedURIs –DuplicateLines –IgnoreExt –ReturnAsObject | Export-Csv “~\Desktop\DuplicateNumbers.csv” –NoTypeInformation [ CmdletBinding ( DefaultParameterSetName = "View" ) ] param ( [ Parameter ( Mandatory = $true , ParameterSetName = "LineSearch" ) ] [ ValidateNotNullOrEmpty ( ) ] [ string ] $LineURI , [ parameter ( ParameterSetName = "LineSearch" ) ] [ switch ] $PartialMatches , [ Parameter ( Mandatory = $true , ParameterSetName = "DuplicateSearch" ) ] [ switch ] $DuplicateLines , [ parameter ( ParameterSetName = "DuplicateSearch" ) ] [ switch ] $IgnoreExt , [ Parameter ( ParameterSetName = "View" ) ] [ switch ] $ReturnNumbers , [ switch ] $NoPrivateLine , [ switch ] $NoWorkflow , [ switch ] $NoCommonArea , [ switch ] $NoUser , [ switch ] $NoAnalogDevice , [ switch ] $NoExUMContact , [ switch ] $NoDialInAcess , [ switch ] $ReutrnAsObject ) $AllNumbers = @ ( ) If ( ! ( ( $NoUser ) -and ( $NoPrivateLine ) ) ) { $Users = Get - CsUser } If ( ! $NoUser ) { $Users | ? { $_ .LineURI -ne "" } | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .DisplayName ; Number = $_ .LineURI ; Type = "User" } } } If ( ! $NoPrivateLine ) { $Users | ? { $_ .PrivateLine -ne "" } | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .DisplayName ; Number = $_ .PrivateLine ; Type = "PrivateLine" } } } If ( ! $NoWorkflow ) { Get - CsRgsWorkflow | Where-Object { $_ .LineURI -ne "" } | Select Name , LineURI | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .Name ; Number = $_ .LineURI ; Type = "Workflow" } } } If ( ! $NoCommonArea ) { Get - CsCommonAreaPhone - Filter { LineURI -ne $null } | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .DisplayName ; Number = $_ .LineURI ; Type = "CommonArea" } } } If ( ! $NoAnalogDevice ) { Get - CsAnalogDevice - Filter { LineURI -ne $null } | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .DisplayName ; Number = $_ .LineURI ; Type = "AnalogDevice" } } } If ( ! $NoExUMContact ) { Get - CsExUmContact - Filter { LineURI -ne $null } | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .DisplayName ; Number = $_ .LineURI ; Type = "ExUmContact" } } } If ( ! $NoDialInAccess ) { Get - CsDialInConferencingAccessNumber - Filter { LineURI -ne $null } | % { $AllNumbers += New-Object PSObject -Property @ { Name = $_ .DisplayName ; Number = $_ .LineURI ; Type = "DialInAccess" } } } If ( $PSCmdlet .ParameterSetName -eq "View" ) { If ( $ReturnAsObject ) { Return $AllNumbers | Sort Name } else { $AllNumbers | Sort Name | Out - GridView -Title "CS Uri Data" } } ElseIf ( $PSCmdlet .ParameterSetName -eq "DuplicateSearch" ) { If ( $IgnoreExt ) { $AllNumbers | % { If ( $_ .Number -like "*ext*" ) { $TrimNum = [ Regex ] ::Matches ( $_ .Number.ToLower ( ) , "tel:(.+?);.+" ) .Groups [ 1 ] .Value } else { $TrimNum = $_ .Number.ToLower ( ) .Replace ( "tel:" , $null ) } $_ | Add-Member -MemberType NoteProperty -Name StdNumber -Value $TrimNum } $DuplicateNumbers = ( ( $AllNumbers | Group-Object StdNumber ) | ? { $_ .Count -gt 1 } ) . Group } else { $DuplicateNumbers = ( ( $AllNumbers | Group-Object Number ) | ? { $_ .Count -gt 1 } ) . Group } If ( $ReturnAsObject ) { Return $DuplicateNumbers | Sort Number } else { $DuplicateNumbers | Sort StdNumber | Out - GridView -Title "Duplicate Numbers" } } ElseIf ( $PSCmdlet .ParameterSetName -eq "LineSearch" ) { $MatchedNumbers = @ ( ) If ( $PartialMatches ) { $MatchedNumbers = $AllNumbers | ? { $_ .Number -like "*$($LineURI)*" } } else { $MatchedNumbers = $AllNumbers | ? { $_ .Number -eq $LineURI } } If ( $ReturnAsObject ) { Return $MatchedNumbers | Sort Number } else { $MatchedNumbers | Sort Number | Out - GridView -Title "Matched Numbers" } } }

RAW Paste Data

Function Get-PoolFQDN { #see if we can grab the sip address from registry, to get the domain. otherwise prompt for it. $Matches = $null Try { $Try16 = (Get-ItemProperty "HKCU:\Software\Microsoft\Office\16.0\Lync" -ErrorAction SilentlyContinue ).ServerSipURI -match ".+@(.+)" IF (!$Try16){ $Try15 = (Get-ItemProperty "HKCU:\Software\Microsoft\Office\15.0\Lync" -ErrorAction SilentlyContinue ).ServerSipURI -match ".+@(.+)"} } Catch { } If ($Matches) { $DomainName = $Matches[1] } Else { $DomainName = Read-Host "Please enter your domain name (e.g. contoso.com)" } #Connect to the LyncDiscoverInternal address for the domain name specified, and retrieves the pool FQDN. $Matches = $null Try { (Invoke-WebRequest "https://LyncDiscoverinternal.$($DomainName)").Content -Match ".+http(?:s?)://(.+?)/.+" > $null } Catch {} If ($Matches){ $PoolFQDN = $Matches[1] } Else { $PoolFQDN = Read-Host "Could not discover pool FQDN, Please enter it manually" } return $poolFQDN } function Connect-LyncSession { param( [string]$PoolFQDN, [switch]$Insecure, $Cred ) #if not specifed, get the pool FQDN automatically (if possible) If (!$PoolFQDN) { $PoolFQDN = Get-PoolFQDN } #attempt to connect to the lync pool, display errors if it fails. Try { $cred.Password.GetType() > $null } Catch { $cred = Get-Credential -Message "Admin credentials for $($PoolFQDN):" } Try { $cred.Password.GetType() > $null $sessionOption = New-PSSessionOption -SkipRevocationCheck If ($Insecure) { $ConnURI = "http://$($PoolFQDN)/OcsPowershell" } Else { $ConnURI = "https://$($PoolFQDN)/OcsPowershell" } $session = New-PSSession -ConnectionURI $ConnURI -Credential $cred -SessionOption $sessionOption -ErrorAction Stop Import-Module (Import-PsSession $session -AllowClobber) -Global } Catch [Exception] { If ($_.Exception.Message.ToString() -like "*null-valued expression*") { Write-Host "Please enter credentials." -ForegroundColor Red } Else { Write-Host "Error Connecting to Lync Server : `r`n" -NoNewLine; Write-Host "$($_.Exception.Message)" -ForegroundColor Red}} } function Get-CsAgentGroupMembership { Param ( [Parameter(Mandatory=$true)] [string]$UserID, [switch]$ReturnGrid, [switch]$ReturnInfo ) #get user $Usr = Get-CsUser $UserID -ErrorAction SilentlyContinue #loop through all groups, check if the user is in any of them. #three return types, default only group names, -ReturnGrid for gridview of all info, -ReturnInfo for array of group objects. If ($Usr -ne $null){ $Groups = @() Get-CsRgsAgentGroup | Where-Object { $_.AgentsByUri -contains $Usr.SipAddress.ToLowerInvariant() } | % { $Groups += $_ } If ($ReturnGrid){ $Groups | Out-GridView -Title "Rgs Group Membership : $($Usr.DisplayName)" } ElseIf ($ReturnInfo) { return $Groups } Else { Return $Groups.Name } } Else { Write-Error "Could not find '$($UserID)'" } } Function Get-CsAssignedURIs { # Get-CsAssignedURIs –LineURI “1234” –PartialMatches # Will return any numbers with ‘1234’ anywhere in them. # Get-CsAssignedURIs –DuplicateLines –IgnoreExt # Will return all duplicate numbers, ignoring any extensions. # Get-CsAssignedURIs –ReturnNumbers (Or nothing specified) # Will return a big list of all numbers assigned in lync. # # -PartialMatches or –IgnoreExt can be excluded, they will return only exact matches (incl. tel:), or check extensions respectively. # # You can also use the –ReturnAsObject parameter with any of these commands, and output it to a file etc.: # Get-CsAssignedURIs –DuplicateLines –IgnoreExt –ReturnAsObject | Export-Csv “~\Desktop\DuplicateNumbers.csv” –NoTypeInformation [CmdletBinding(DefaultParameterSetName = "View")] param( [Parameter(Mandatory=$true, ParameterSetName="LineSearch")] [ValidateNotNullOrEmpty()] [string]$LineURI, [parameter(ParameterSetName="LineSearch")] [switch]$PartialMatches, [Parameter(Mandatory=$true, ParameterSetName="DuplicateSearch")] [switch]$DuplicateLines, [parameter(ParameterSetName="DuplicateSearch")] [switch]$IgnoreExt, [Parameter(ParameterSetName="View")] [switch]$ReturnNumbers, [switch]$NoPrivateLine, [switch]$NoWorkflow, [switch]$NoCommonArea, [switch]$NoUser, [switch]$NoAnalogDevice, [switch]$NoExUMContact, [switch]$NoDialInAcess, [switch]$ReutrnAsObject ) $AllNumbers = @() If (!(($NoUser) -and ($NoPrivateLine))) { $Users = Get-CsUser } If (!$NoUser){ $Users | ? {$_.LineURI -ne ""} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; Number = $_.LineURI ; Type = "User" }}} If (!$NoPrivateLine){ $Users | ? {$_.PrivateLine -ne ""} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; Number = $_.PrivateLine ; Type = "PrivateLine" }}} If (!$NoWorkflow){ Get-CsRgsWorkflow | Where-Object {$_.LineURI -ne ""} | Select Name,LineURI | %{$AllNumbers += New-Object PSObject -Property @{Name = $_.Name ; Number = $_.LineURI ; Type = "Workflow" }}} If (!$NoCommonArea){ Get-CsCommonAreaPhone -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; Number = $_.LineURI ; Type = "CommonArea" }}} If (!$NoAnalogDevice){ Get-CsAnalogDevice -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; Number = $_.LineURI ; Type = "AnalogDevice" }}} If (!$NoExUMContact){ Get-CsExUmContact -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; Number = $_.LineURI ; Type = "ExUmContact" }}} If (!$NoDialInAccess){ Get-CsDialInConferencingAccessNumber -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; Number = $_.LineURI ; Type = "DialInAccess" }}} If ($PSCmdlet.ParameterSetName -eq "View"){ If ($ReturnAsObject) { Return $AllNumbers | Sort Name } else { $AllNumbers | Sort Name | Out-GridView -Title "CS Uri Data" } } ElseIf ($PSCmdlet.ParameterSetName -eq "DuplicateSearch") { If ($IgnoreExt) { $AllNumbers | % { If ($_.Number -like "*ext*"){ $TrimNum = [Regex]::Matches($_.Number.ToLower(),"tel:(.+?);.+").Groups[1].Value } else { $TrimNum = $_.Number.ToLower().Replace("tel:",$null) } $_ | Add-Member -MemberType NoteProperty -Name StdNumber -Value $TrimNum } $DuplicateNumbers = (($AllNumbers | Group-Object StdNumber) | ? {$_.Count -gt 1}).Group } else { $DuplicateNumbers = (($AllNumbers | Group-Object Number) | ? {$_.Count -gt 1}).Group } If ($ReturnAsObject) { Return $DuplicateNumbers | Sort Number } else { $DuplicateNumbers | Sort StdNumber | Out-GridView -Title "Duplicate Numbers" } } ElseIf ($PSCmdlet.ParameterSetName -eq "LineSearch") { $MatchedNumbers = @() If ($PartialMatches) { $MatchedNumbers = $AllNumbers | ? { $_.Number -like "*$($LineURI)*" } } else { $MatchedNumbers = $AllNumbers | ? { $_.Number -eq $LineURI } } If ($ReturnAsObject) { Return $MatchedNumbers | Sort Number } else { $MatchedNumbers | Sort Number | Out-GridView -Title "Matched Numbers" }} }