LUM.SfB.psm1
function format-hours{ param( $businessHours, $day, $prepend ) If(($businesshours."$($day)hours1".closetime.Totalminutes -eq 0) -and ($businesshours."$($day)hours2".closetime.Totalminutes -eq 1439)){ $x = "Open all day on $prepend" write-host $x -ForegroundColor Green return } If(($businesshours."$($day)hours1".closetime.Totalminutes -eq 1439) -and ($businesshours."$($day)hours2".closetime.Totalminutes -eq 0)){ $x = "Open all day on $prepend" write-host $x -ForegroundColor Green return } If(($businesshours."$($day)hours1".closetime.Totalminutes -eq $null) -and ($businesshours."$($day)hours2".closetime.Totalminutes -eq 1439)){ $x = "Open all day on $prepend" write-host $x -ForegroundColor Green return } If(($businesshours."$($day)hours1".closetime.Totalminutes -eq 1439) -and ($businesshours."$($day)hours2".closetime.Totalminutes -eq $null)){ $x = "Open all day on $prepend" write-host $x -ForegroundColor Green return } If(($businesshours."$($day)hours1".opentime.Totalminutes -eq $businesshours."$($day)hours1".closetime.Totalminutes) -and ($businesshours."$($day)hours2".opentime.Totalminutes -eq $businesshours."$($day)hours2".closetime.Totalminutes)){ $x = "Closed all day on $prepend" write-host $x -ForegroundColor Red return } If(($businesshours."$($day)hours1".opentime.Totalminutes -eq $businesshours."$($day)hours1".closetime.Totalminutes) -and ($businesshours."$($day)hours2".opentime.Totalminutes -ne $businesshours."$($day)hours2".closetime.Totalminutes)){ $openH2 = $businesshours."$($day)hours2".opentime.hours if($openH2 -lt 10){$openH2 = "0$($openH2.tostring())"} $openM2 = $businesshours."$($day)hours2".opentime.minutes if($openM2 -lt 10){$openM2 = "0$($openM2.tostring())"} $closeH2 = $businesshours."$($day)hours2".closetime.hours if($closeH2 -lt 10){$closeH2 = "0$($closeH2.tostring())"} $closeM2 = $businesshours."$($day)hours2".closetime.minutes if($closeM2 -lt 10){$closeM2 = "0$($closeM2.tostring())"} write-host "From $($openH2):$openM2 to $($closeH2):$closeM2 on $prepend" -ForegroundColor Cyan } If(($businesshours."$($day)hours1".opentime.Totalminutes -ne $businesshours."$($day)hours1".closetime.Totalminutes) -and ($businesshours."$($day)hours2".opentime.Totalminutes -eq $businesshours."$($day)hours2".closetime.Totalminutes)){ $openH1 = $businesshours."$($day)hours1".opentime.hours if($openH1 -lt 10){$openH1 = "0$($openH1.tostring())"} $openM1 = $businesshours."$($day)hours1".opentime.minutes if($openM1 -lt 10){$openM1 = "0$($openM1.tostring())"} $closeH1 = $businesshours."$($day)hours1".closetime.hours if($closeH1 -lt 10){$closeH1 = "0$($closeH1.tostring())"} $closeM1 = $businesshours."$($day)hours1".closetime.minutes if($closeM1 -lt 10){$closeM1 = "0$($closeM1.tostring())"} write-host "From $($openH1):$openM1 to $($closeH1):$closeM1 on $prepend" -ForegroundColor Cyan } If(($businesshours."$($day)hours1".opentime.Totalminutes -ne $businesshours."$($day)hours1".closetime.Totalminutes) -and ($businesshours."$($day)hours2".opentime.Totalminutes -ne $businesshours."$($day)hours2".closetime.Totalminutes)){ $openH1 = $businesshours."$($day)hours1".opentime.hours if($openH1 -lt 10){$openH1 = "0$($openH1.tostring())"} $openM1 = $businesshours."$($day)hours1".opentime.minutes if($openM1 -lt 10){$openM1 = "0$($openM1.tostring())"} $closeH1 = $businesshours."$($day)hours1".closetime.hours if($closeH1 -lt 10){$closeH1 = "0$($closeH1.tostring())"} $closeM1 = $businesshours."$($day)hours1".closetime.minutes if($closeM1 -lt 10){$closeM1 = "0$($closeM1.tostring())"} $openH2 = $businesshours."$($day)hours2".opentime.hours if($openH2 -lt 10){$openH2 = "0$($openH2.tostring())"} $openM2 = $businesshours."$($day)hours2".opentime.minutes if($openM2 -lt 10){$openM2 = "0$($openM2.tostring())"} $closeH2 = $businesshours."$($day)hours2".closetime.hours if($closeH2 -lt 10){$closeH2 = "0$($closeH2.tostring())"} $closeM2 = $businesshours."$($day)hours2".closetime.minutes if($closeM2 -lt 10){$closeM2 = "0$($closeM2.tostring())"} write-host "From $($openH1):$openM1 to $($closeH1):$closeM1 and from $($openH2):$openM2 to $($closeH2):$closeM2 on $prepend" -ForegroundColor Cyan } } # This Function Returns the Selected Value and Closes the Form function Return-DropDown { if ($DropDown.SelectedItem -eq $null){ $DropDown.SelectedItem = $DropDown.Items[0] $script:Choice = $DropDown.SelectedItem.ToString() $Form.Close() } else{ $script:Choice = $DropDown.SelectedItem.ToString() $Form.Close() } } function SelectGroup{ [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") $Form = New-Object System.Windows.Forms.Form $Form.width = 500 $Form.height = 150 $Form.Text = �DropDown� $DropDown = new-object System.Windows.Forms.ComboBox $DropDown.Location = new-object System.Drawing.Size(200,10) $DropDown.Size = new-object System.Drawing.Size(260,30) [void] $DropDown.Items.Add("Multiple_Response_Groups") ForEach ($Item in $DropDownArray) { [void] $DropDown.Items.Add($Item) } $Form.Controls.Add($DropDown) $DropDownLabel = new-object System.Windows.Forms.Label $DropDownLabel.Location = new-object System.Drawing.Size(10,10) $DropDownLabel.size = new-object System.Drawing.Size(100,40) $DropDownLabel.Text = "Select Group:" $Form.Controls.Add($DropDownLabel) $Button = new-object System.Windows.Forms.Button $Button.Location = new-object System.Drawing.Size(100,50) $Button.Size = new-object System.Drawing.Size(100,20) $Button.Text = "Select an Item" $Button.Add_Click({Return-DropDown}) $form.Controls.Add($Button) $form.ControlBox = $false $Form.Add_Shown({$Form.Activate()}) [void] $Form.ShowDialog() return $script:choice } function Get-RgsWorkflow{ <# .SYNOPSIS Displays one or more RGS workflows .DESCRIPTION Shows Workflow to queue to group with all parameters .EXAMPLE Get-RgsWorkflow .INPUTS Selection of RGSWorkflow Name .OUTPUTS Report on workflow in Write-Host .NOTES +---------------------------------------------------------------------------------------------+ | ORIGIN STORY | +---------------------------------------------------------------------------------------------+ | DATE : 2018.10.29 | AUTHOR : Michael L�rsen | E-Mail : michael.luersen@mondaycoffee.com +---------------------------------------------------------------------------------------------+ #> if(!(get-module SkypForBusiness)){ Import-Module SkypeForBusiness } if($psise -ne $null){ Write-Warning "the formatting looks better when you run this cmd-let from the Console instead ISE" } [array]$DropDownArrayItems = (get-csrgsworkflow).name [array]$DropDownArray = $DropDownArrayItems | sort $Group = $null $Group = SelectGroup while ($Group -like ""){ $Group = SelectGroup } if($group -eq "Multiple_Response_Groups"){ $prefix = read-host -Prompt "Type the first letter(s) of the response group for which to return results" $rgsworkflows = get-csrgsworkflow | Where-Object{$_.name -like "$prefix*"} }else{ $rgsworkflows = get-csrgsworkflow -name $group } foreach($rgsworkflow in $rgsworkflows){ $rgsqueue = Get-CsRgsQueue | Where-Object{$_.identity.instanceID.guid -eq $rgsworkflow.DefaultAction.QueueID.InstanceId} $rgsgroups = @() foreach($agentGroup in $rgsqueue.AgentGroupIDList){ $rgsgroups += Get-CsRgsAgentGroup | where-object{$_.identity.instanceid.guid -eq $agentgroup.instanceID.Guid} } write-host "`n======== GENERAL INFO ========" -BackgroundColor Gray if($Rgsworkflow.Active -eq $true){ write-host "workflow is active" -ForegroundColor Green }else{ write-host "workflow is inactive" -ForegroundColor Gray } if($Rgsworkflow.EnabledForFederation -eq $true){ write-host "workflow is enabled for federation" -ForegroundColor Green }else{ write-host "workflow is not enabled for federation" -ForegroundColor Gray } if($Rgsworkflow.Anonymous -eq $true){ write-host "workflow is enabled for agent anonymity" -ForegroundColor Green }else{ write-host "workflow is not enabled for agent anonymity" -ForegroundColor Gray } write-host "Sip Address: `t`t $($rgsworkflow.primaryuri)" -ForegroundColor Cyan write-host "Displayname: `t`t $($rgsworkflow.name)" -ForegroundColor Cyan write-host "Telephone Number: `t $($rgsworkflow.Lineuri)" -ForegroundColor Cyan write-host "DisplayNumber: `t`t $($rgsworkflow.DisplayNumber)" -ForegroundColor Cyan if($rgsworkflow.Description -ne $null){ write-host "Description: `t`t $($rgsworkflow.Description)" -ForegroundColor Cyan } if($Rgsworkflow.managed -eq $true){ write-host "workflow type is managed by:" -ForegroundColor Green foreach($manager in $rgsworkflow.ManagersByUri){ write-host "`t`t`t$manager" -ForegroundColor Cyan } }else{ write-host "workflow type is unmanaged" -ForegroundColor Gray } write-host "`n======== Language ========" -BackgroundColor Gray write-host "Workflow Language: `t $($rgsworkflow.Language)" -ForegroundColor Cyan write-host "`n======== Welcome Message ========" -BackgroundColor Gray if($rgsworkflow.DefaultAction.Prompt.AudioFilePrompt -ne $null){ write-host "Audiofile: `t`t $($rgsworkflow.DefaultAction.Prompt.AudioFilePrompt)" -ForegroundColor Cyan } if($rgsworkflow.DefaultAction.Prompt.TextToSpeechPrompt -ne $null){ write-host "Text to Speech: `t`t $($rgsworkflow.DefaultAction.Prompt.TextToSpeechPrompt)" -ForegroundColor Cyan } write-host "`n======== Business Hours ========" -BackgroundColor Gray if($rgsworkflow.NonBusinessHoursAction.Prompt.AudioFilePrompt -ne $null){ write-host "Message outside of business hours - Audiofile: `t`t $($rgsworkflow.NonBusinessHoursAction.Prompt.AudioFilePrompt)" -ForegroundColor Cyan } if($($rgsworkflow.NonBusinessHoursAction.Prompt.TextToSpeechPrompt).length -ne 0){ write-host "Message outside of business hours - Text to Speech: `t`t $($rgsworkflow.NonBusinessHoursAction.Prompt.TextToSpeechPrompt)" -ForegroundColor Cyan } write-host "Action outside of business hours: `t $($rgsworkflow.NonBusinessHoursAction.action)" -ForegroundColor Cyan $businesshours = Get-CsRgsHoursOfBusiness -Identity $rgsworkflow.BusinessHoursID if(($businesshours.MondayHours1.OpenTime -eq $businesshours.TuesdayHours1.OpenTime) -and ($businesshours.MondayHours1.CloseTime -eq $businesshours.TuesdayHours1.CloseTime) -and ($businesshours.MondayHours2.OpenTime -eq $businesshours.TuesdayHours2.OpenTime) -and ($businesshours.MondayHours2.CloseTime -eq $businesshours.TuesdayHours2.CloseTime)){ if(($businesshours.TuesdayHours1.OpenTime -eq $businesshours.WednesdayHours1.OpenTime) -and ($businesshours.TuesdayHours1.CloseTime -eq $businesshours.WednesdayHours1.CloseTime) -and ($businesshours.TuesdayHours2.OpenTime -eq $businesshours.WednesdayHours2.OpenTime) -and ($businesshours.TuesdayHours2.CloseTime -eq $businesshours.WednesdayHours2.CloseTime)){ if(($businesshours.WednesdayHours1.OpenTime -eq $businesshours.ThursdayHours1.OpenTime) -and ($businesshours.WednesdayHours1.CloseTime -eq $businesshours.ThursdayHours1.CloseTime) -and ($businesshours.WednesdayHours2.OpenTime -eq $businesshours.ThursdayHours2.OpenTime) -and ($businesshours.WednesdayHours2.CloseTime -eq $businesshours.ThursdayHours2.CloseTime)){ if(($businesshours.ThursdayHours1.OpenTime -eq $businesshours.FridayHours1.OpenTime) -and ($businesshours.ThursdayHours1.CloseTime -eq $businesshours.FridayHours1.CloseTime) -and ($businesshours.ThursdayHours2.OpenTime -eq $businesshours.FridayHours2.OpenTime) -and ($businesshours.ThursdayHours2.CloseTime -eq $businesshours.FridayHours2.CloseTime)){ if(($businesshours.FridayHours1.OpenTime -eq $businesshours.SaturdayHours1.OpenTime) -and ($businesshours.FridayHours1.CloseTime -eq $businesshours.SaturdayHours1.CloseTime) -and ($businesshours.FridayHours2.OpenTime -eq $businesshours.SaturdayHours2.OpenTime) -and ($businesshours.FridayHours2.CloseTime -eq $businesshours.SaturdayHours2.CloseTime)){ if(($businesshours.SaturdayHours1.OpenTime -eq $businesshours.SundayHours1.OpenTime) -and ($businesshours.SaturdayHours1.CloseTime -eq $businesshours.SundayHours1.CloseTime) -and ($businesshours.SaturdayHours2.OpenTime -eq $businesshours.SundayHours2.OpenTime) -and ($businesshours.SaturdayHours2.CloseTime -eq $businesshours.SundayHours2.CloseTime)){ format-hours -businessHours $businesshours -day "Sunday" -prepend "Monday - Sunday" }Else{ format-hours -businessHours $businesshours -day "Saturday" -prepend "Monday - Saturday" format-hours -businessHours $businesshours -day "Sunday" -prepend "Sunday: " } }Else{ format-hours -businessHours $businesshours -day "Friday" -prepend "Monday - Friday" format-hours -businessHours $businesshours -day "Saturday" -prepend "Saturday" format-hours -businessHours $businesshours -day "Sunday" -prepend "Sunday" } }Else{ format-hours -businessHours $businesshours -day "Thursday" -prepend "Monday - Thursday" format-hours -businessHours $businesshours -day "Friday" -prepend "Friday" format-hours -businessHours $businesshours -day "Saturday" -prepend "Saturday" format-hours -businessHours $businesshours -day "Sunday" -prepend "Sunday" } }Else{ format-hours -businessHours $businesshours -day "Wednesday" -prepend "Monday - Wednesday" format-hours -businessHours $businesshours -day "Thursday" -prepend "Thursday" format-hours -businessHours $businesshours -day "Friday" -prepend "Friday" format-hours -businessHours $businesshours -day "Saturday" -prepend "Saturday" format-hours -businessHours $businesshours -day "Sunday" -prepend "Sunday" } }Else{ format-hours -businessHours $businesshours -day "Tuesday" -prepend "Monday - Wednesday" format-hours -businessHours $businesshours -day "Wednesday" -prepend "Wednesday" format-hours -businessHours $businesshours -day "Thursday" -prepend "Thursday" format-hours -businessHours $businesshours -day "Friday" -prepend "Friday" format-hours -businessHours $businesshours -day "Saturday" -prepend "Saturday" format-hours -businessHours $businesshours -day "Sunday" -prepend "Sunday" } } Else{ format-hours -businessHours $businesshours -day "Monday" -prepend "Monday" format-hours -businessHours $businesshours -day "Tuesday" -prepend "Tuesday" format-hours -businessHours $businesshours -day "Wednesday" -prepend "Wednesday" format-hours -businessHours $businesshours -day "Thursday" -prepend "Thursday" format-hours -businessHours $businesshours -day "Friday" -prepend "Friday" format-hours -businessHours $businesshours -day "Saturday" -prepend "Saturday" format-hours -businessHours $businesshours -day "Sunday" -prepend "Sunday" } write-host "`n======== Holidays ========" -BackgroundColor Gray foreach($item in $rgsworkflow.HolidaySetIDList){ $service = (get-csservice | ?{$_.serviceID -eq $($item.ServiceId)}).identity $identity = $service + "/" + $item.instanceid write-host (Get-CsRgsHolidaySet -Identity $identity).name -ForegroundColor Cyan } write-host "`n======== Connected queue ========" -BackgroundColor Gray $rgsqueuename = (get-csrgsqueue -Identity $rgsworkflow.DefaultAction.QueueID).name write-host $rgsqueuename -ForegroundColor Cyan write-host "`n======== Music on Hold ========" -BackgroundColor Gray write-host $rgsworkflow.CustomMusicOnHoldFile.OriginalFileName -ForegroundColor Cyan write-host "`n======== Queue settings ========" -BackgroundColor Gray $rgsqueue = Get-CsRgsQueue -Name $rgsqueuename write-host "Name: `t`t`t`t`t" $rgsqueue.name -ForegroundColor Cyan if($rgsqueue.Description -ne $null){ write-host "Description: `t`t`t`t" $rgsqueue.Description -ForegroundColor Cyan } if($rgsqueue.TimeoutThreshold -ne $null){ write-host "Queue Timeout Seconds: `t`t`t" $rgsqueue.TimeoutThreshold -ForegroundColor Cyan write-host "Queue Timeout Action: `t`t`t" $rgsqueue.Timeoutaction.action -ForegroundColor Cyan if($rgsqueue.Timeoutaction.Prompt -ne $null){ write-host "Queue Timeout Prompt: `t`t`t" $rgsqueue.Timeoutaction.Prompt -ForegroundColor Cyan } if($rgsqueue.Timeoutaction.Question -ne $null){ write-host "Queue Timeout Question: `t`t`t" $rgsqueue.Timeoutaction.Question -ForegroundColor Cyan } if($rgsqueue.Timeoutaction.QueueID -ne $null){ $rgsTimeoutqueuename = (get-csrgsqueue -Identity $rgsqueue.Timeoutaction.QueueID).name write-host "Queue Timeout Forward Queue: `t`t" $rgsTimeoutqueuename -ForegroundColor Cyan } if($rgsqueue.Timeoutaction.Uri -ne $null){ write-host "Queue Timeout Forward to: `t`t" $rgsqueue.Timeoutaction.Uri -ForegroundColor Cyan } } If($rgsqueue.OverflowThreshold -ne $null){ write-host "Queue Overflow Threshold: `t`t" $rgsqueue.OverflowThreshold -ForegroundColor Cyan if($rgsqueue.OverflowCandidate -ne $null){ write-host "Queue Overflow Candidate: `t`t" $rgsqueue.OverflowCandidate -ForegroundColor Cyan } if($rgsqueue.OverflowAction.Prompt -ne $null){ write-host "Queue Overflow Prompt: `t`t" $rgsqueue.OverflowAction.Prompt -ForegroundColor Cyan } if($rgsqueue.OverflowAction.Question -ne $null){ write-host "Queue Overflow Question: `t`t" $rgsqueue.OverflowAction.Question -ForegroundColor Cyan } if($rgsqueue.OverflowAction.QueueID -ne $null){ $rgsOverflowqueuename = (get-csrgsqueue -Identity $rgsqueue.OverflowAction.QueueID).name write-host "Queue Overflow Forward Queue: `t`t`t" $rgsOverflowqueuename -ForegroundColor Cyan } if($rgsqueue.OverflowAction.Uri -ne $null){ write-host "Queue Overflow Forward to: `t`t" $rgsqueue.OverflowAction.Uri -ForegroundColor Cyan } } write-host "`n======== Groups & Agents ========" -BackgroundColor Gray foreach($item in $rgsqueue.AgentGroupIDList){ $service = (get-csservice | ?{$_.serviceID -eq $($item.ServiceId)}).identity $identity = $service + "/" + $item.instanceid $agentgroup = (Get-CsRgsAgentGroup -Identity $identity) write-host "Agent group Name: `t`t`t" $agentgroup.name -ForegroundColor Cyan write-host "Agent group Alert Time: `t`t" $agentgroup.AgentAlertTime -ForegroundColor Cyan if($agentGroup.Description -ne $null){ write-host "Agent group Description: `t" $agentgroup.Description -ForegroundColor Cyan } write-host "Agent group participation policy: `t" $agentgroup.ParticipationPolicy -ForegroundColor Cyan write-host "Agent group routing method: `t`t" $agentgroup.RoutingMethod -ForegroundColor Cyan $x = $false foreach($member in $agentGroup.agentsbyURI){ $agent = $member.ToString() if($x -eq $false){ $x = $true write-host "Agent group members: `t`t`t" $agent.Replace("sip:","") -ForegroundColor Green }else{ write-host "`t`t`t`t`t" $agent.Replace("sip:","") -ForegroundColor Green } } } } write-host "`n`n" Read-Host -Prompt "Press Enter to exit" } function Get-SfbAssignedNumbers{ <# .SYNOPSIS Exports all assigned numbers from SfB / AudioCodes .DESCRIPTION Shows Workflow to queue to group with all parameters .PARAMETER audiocodesIniDir One or more directories containing ini backup files from Audiocodes SBCs .PARAMETER outputDir Path where the output is stored .PARAMETER SfbOnline Switch - if enabled it will go to sfbOnline. Required overrideAdminDomain and Numberblocks parameters .PARAMETER overrideAdminDomain String with overRideDOmainAdmin parameter from New-CsOnlineSession cmdlet. Required with SfbOnline .PARAMETER numberBlocks Array of strings, required with SfbOnline. Enter as: "+41441234560,+41441234569","etc... .PARAMETER gatewayType Name that will be given to numbers routed to a gateway (Default value is DECT) .PARAMETER lanInterfaceName Interface name of the internal LAN interface in Audiocodes (Default value is SIP_LAN) .PARAMETER mucIpGroupname IP Group Name of the SfB group (Default value is SfB) .PARAMETER reduce When an unassigned number range is configured with +99, this will be reduced by 58000000000 by default to end up with a +41 number. Change accordingly if you have a different country code. Assumption is made that you have a 12 digit number including the +. Reason for including a +99 unassigned number range can be that you want internal callers calling this range be sent back to the SBC instead of to the unassigned number target. For example pre-migration scenarios or where part of the range belongs to numbers from the gateway. .EXAMPLE Get-RgsWorkflow -audiocodesDir 'c:\Audiocodes\Backup\10.0.0.10\','c:\Audiocodes\Backup\10.0.0.12\' -outputDir 'c:\SfB\AssignedNumbers\' .EXAMPLE Get-RgsWorkflow -audiocodesDir 'c:\Audiocodes\Backup\10.0.0.10\' -outputDir 'c:\SfB\AssignedNumbers\' -gatewayType 'PRI_Phones' -lanInterfaceName 'Internal' -mucIpGroupname 'Lync' -reduce 56000000000 .INPUTS Parameters .OUTPUTS file in outputdir\history containing assigned number range files file .\outputdir\SfbAssignedNumbers.csv containing currently assigned numbers file .\outputdir\AvailableNumbers.csv containing unassigned numbers based on unassigned number ranges and assignedNumbers .NOTES +---------------------------------------------------------------------------------------------+ | ORIGIN STORY | +---------------------------------------------------------------------------------------------+ | DATE : 2018.10.29 | AUTHOR : Michael L�rsen | E-Mail : michael.luersen@mondaycoffee.com +---------------------------------------------------------------------------------------------+ #> # # This script queries Lync for all assigned numbers and displays in a formatted table with the option to export to CSV. # During processing LineURI's are run against a regex pattern to extract the DDI/DID and the extension to a separate column. # # Numbers Queried: LineURI, Private Line, Analouge Lines, Common Area Phones, RGS Workflows, Exchange UM Contacts, Trusted Applications and Conferencing Numbers # Also queries the Fax number from a backup the audiocodes gateway, as well as gateway numbers, which as displayed as DECT as those are typically Param( [CmdletBinding( SupportsShouldProcess=$false, PositionalBinding=$false, ConfirmImpact='Low')] [Parameter(Mandatory=$true)] $audiocodesIniDir, [switch]$SfbOnline, [string]$overrideAdminDomain, [string[]]$numberBlocks, [Parameter(Mandatory=$true)] [string]$outputDir, [Parameter(Mandatory=$false)] [string]$gatewayType = 'DECT', [Parameter(Mandatory=$false)] [string]$lanInterfaceName = 'SIP_LAN', [Parameter(Mandatory=$false)] [string]$mucIpGroupname = 'SfB', [Parameter(Mandatory=$false)] [double]$reduce = 58000000000 ) if($outputDir.Substring($outputDir.Length -1) -ne "\"){ $outputDir = $outputDir + '\' } if(!(test-path $audiocodesIniDir)){ Write-Error -Message 'audiocodesIniDir does not exist' break } if(!(test-path $outputDir)){ Write-Error -Message 'outputDir does not exist' break } if(!(test-path "$($outputDir)\History")){ Write-Warning -Message 'History dir does not exist, creating a new one...' New-Item -ItemType Directory -path "$($outputDir)\History" } if(!(test-path "$($outputDir)\Keys")){ Write-Warning -Message 'Keys dir does not exist, creating a new one...' New-Item -ItemType Directory -path "$($outputDir)\Keys" } if($SfbOnline){ if(!$overrideAdminDomain){ Write-Error -Message 'overrideAdminDomain is required when using o365. Exiting' break } if(!$numberBlocks){ Write-Error -Message 'numberBlocks is required when using o365. Exiting' break } } $FileName = "SfbAssignedNumbers_" + (Get-Date -Format s).replace(":","-") +".csv" $FilePath = "$($outputDir)History\$FileName" $FilePath2 = "$($outputDir)SfbAssignedNumbers.csv" if(!$SfbOnline){ if(!(get-module SkypForBusiness)){ Import-Module SkypeForBusiness } if(!(get-module Lync)){ Import-Module Lync } }else{ if(!(get-module LyncOnlineConnector)){ Import-Module LyncOnlineConnector } $passwordfile = "$outputDir\Keys\SfbOnlinekey.xml" if(!(test-path $passwordfile)){ $credential = Get-Credential -Message "Enter Credentials for o365" $credential | Export-CliXml -Path $passwordfile } $credential = Import-CliXml -Path $passwordfile $session = New-CsOnlineSession -Credential $credential �OverrideAdminDomain $overrideAdminDomain Import-PSSession $session -AllowClobber } $Regex1 = '^(?:tel:)?(?:\+)?(\d+)(?:;ext=(\d+))?(?:;([\w-]+))?$' $Array1 = @() #Get Fax numbers #get most recent ini file $ipRouting = $null $inboundManipulation = $null foreach($backupPath in $audiocodesIniDir){ $backupFile = get-content (Get-ChildItem -path $backupPath -filter "*.ini" | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1).fullname $ipRoutingMatch = $false $inboundManipulationMatch = $false foreach($line in $backupFile){ #Catch iprouting lines for fax and dect ranges if($line -eq '[ \IP2IPRouting ]'){ #stop capturing strings after this $ipRoutingMatch = $false } if($ipRoutingMatch -eq $true){ #capture strings $ipRouting += $line $ipRouting += "`n" } if($line -eq '[ IP2IPRouting ]'){ #start capturing strings $ipRoutingMatch = $true } # Catch Inbound manipulation lines for Office 365 Workflows if($line -eq '[ \IPInboundManipulation ]'){ #stop capturing strings after this $inboundManipulationMatch = $false } if($inboundManipulationMatch -eq $true){ #capture strings $inboundManipulation += $line $inboundManipulation += "`n" } if($line -eq '[ IPInboundManipulation ]'){ #start capturing strings $inboundManipulationMatch = $true } } } If($SfbOnline){ $inboundManipulation = $inboundManipulation.Replace(" = ",",") $inboundManipulation = $inboundManipulation.trim() $inboundManipulation = ConvertFrom-Csv $inboundManipulation -Delimiter "," foreach($item in $inboundManipulation){ $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $item.IPInboundManipulation_DestUsernamePrefix $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $item.IPInboundManipulation_DestUsernamePrefix.replace("+","") $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value "" $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.IPInboundManipulation_ManipulationName $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value "" $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value "" $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "Workflow" $Array1 += $myObject1 } } $ipRouting = $ipRouting.trim() $ipRouting = ConvertFrom-Csv $ipRouting -Delimiter "," #select only fax numbers (not going to SfB and no empty lines) #include a destination type of 8 so that numbers sent to the gateway (ie. DECT) are included too. $faxNumbers = $ipRouting | Where-Object{$_.IP2IPRouting_DestSipInterfaceName -eq $lanInterfaceName -and ($_.IP2IPRouting_DestIPGroupName -notin $mucIpGroupname,'' -or $_.IP2IPRouting_DestType -eq 8)} foreach($item in $faxNumbers){ if($item.IP2IPRouting_DestUsernamePrefix.IndexOf('[') -ne -1){ #add lines for ranges and series $number = $item.IP2IPRouting_DestUsernamePrefix.split('[')[0] $number = $number.replace('+','') if( ($item.IP2IPRouting_DestUsernamePrefix.split('[')[1]).trim(']').indexof('-') -ne -1){ #found a - in the [] // create a range $range = ($item.IP2IPRouting_DestUsernamePrefix.split('[')[1]).trim(']').split('-') $range[0]..$range[1] | foreach-object{ $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $item.IP2IPRouting_DestUsernamePrefix if($_ -lt 10){ $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value "$($number)0$($_)" }else{ $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $number$_ } $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value "" $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.IP2IPRouting_DestIPGroupName $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value "" $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value "" if($item.IP2IPRouting_DestType -eq 8){ $myObject1 | Add-Member -type NoteProperty -name "Type" -Value $gatewayType }Else{ $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "Fax" } $Array1 += $myObject1 } } if( ($item.IP2IPRouting_DestUsernamePrefix.split("[")[1]).trim("]").indexof(",") -ne -1){#found a , in the [] // create a series $range = ($item.IP2IPRouting_DestUsernamePrefix.split("[")[1]).trim("]").split(",") foreach($thing in $range){ $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $item.IP2IPRouting_DestUsernamePrefix $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $number$thing $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value "" $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.IP2IPRouting_DestIPGroupName $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value "" $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value "" if($item.IP2IPRouting_DestType -eq 8){ $myObject1 | Add-Member -type NoteProperty -name "Type" -Value $gatewayType }Else{ $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "Fax" } $Array1 += $myObject1 } } } Else{# just add the number as is $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $item.IP2IPRouting_DestUsernamePrefix $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $item.IP2IPRouting_DestUsernamePrefix.replace("+","") $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value "" $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.IP2IPRouting_DestIPGroupName $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value "" $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value "" if($item.IP2IPRouting_DestType -eq 8){ $myObject1 | Add-Member -type NoteProperty -name "Type" -Value $gatewayType }Else{ $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "Fax" } $Array1 += $myObject1 } } if(!$SfbOnline){ # do all the onprem stuff #Get Users with LineURI $UsersLineURI = Get-CsUser -Filter {LineURI -ne $Null} if($UsersLineURI -ne $null){ foreach($item in $UsersLineURI) { $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value $Item.FirstName $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value $Item.LastName $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "User" $Array1 += $myObject1 } } #Get Users with Private Line $UsersPrivateLine = Get-CsUser -Filter {PrivateLine -ne $Null} if($UsersPrivateLine -ne $null){ foreach($item in $UsersPrivateLine) { $Matches = @() $Item.PrivateLine -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.PrivateLine $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "FirstName" -Value $Item.FirstName $myObject1 | Add-Member -type NoteProperty -name "LastName" -Value $Item.LastName $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "UserPrivateLine" $Array1 += $myObject1 } } #Get analouge lines $AnalougeLineURI = Get-CsAnalogDevice -Filter {LineURI -ne $Null} if($AnalougeLineURI -ne $null){ foreach($item in $AnalougeLineURI) { $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "AnalougeLine" $Array1 += $myObject1 } } #Get common area phones $CommonAreaLineURI = Get-CsCommonAreaPhone -Filter {LineURI -ne $Null} if($CommonAreaLineURI -ne $null){ foreach($item in $CommonAreaLineURI) { $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "CommonArea" $Array1 += $myObject1 } } #Get RGS workflows $WorkflowLineURI = Get-CsRgsWorkflow if($WorkflowLineURI -ne $null){ foreach($item in $WorkflowLineURI) { $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "RGSWorkflow" $Array1 += $myObject1 } } #Get Exchange UM Contacts $ExUmContactLineURI = Get-CsExUmContact -Filter {LineURI -ne $Null} if($ExUmContactLineURI -ne $null){ foreach($item in $ExUmContactLineURI) { $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "ExUmContact" $Array1 += $myObject1 } } #Get trusted applications $TrustedApplicationLineURI = Get-CsTrustedApplicationEndpoint -Filter {LineURI -ne $Null} if($TrustedApplicationLineURI -ne $null){ foreach($item in $TrustedApplicationLineURI){ $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.Name $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "TrustedApplication" $Array1 += $myObject1 } } #Get conferencing numbers $DialInConfLineURI = Get-CsDialInConferencingAccessNumber -Filter {LineURI -ne $Null} if($DialInConfLineURI -ne $null){ foreach($Item in $DialInConfLineURI){ $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.LineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.DisplayName $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "DialInConf" $Array1 += $myObject1 } } } if($SfbOnline){ #do the online stuff $users = Get-CsOnlineUser -Filter {OnPremLineURI -ne $Null} � � � � foreach($item in $users){ $Matches = @() $Item.LineURI -match $Regex1 | out-null $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "LineURI" -Value $Item.OnPremLineURI $myObject1 | Add-Member -type NoteProperty -name "DDI" -Value $Matches[1] $myObject1 | Add-Member -type NoteProperty -name "Ext" -Value $Matches[2] $myObject1 | Add-Member -type NoteProperty -name "Name" -Value $Item.SipProxyAddress $myObject1 | Add-Member -type NoteProperty -name "Type" -Value "User" $Array1 += $myObject1 } } $Array1 | export-csv $FilePath -NoTypeInformation -Encoding unicode $Array1 | export-csv $FilePath2 -NoTypeInformation -Encoding unicode -force Write-Host "ALL DONE!! Your file has been saved to $FilePath" Write-Host "Creating available numbers list" Remove-Item -path "$outputDir\Available-numbers.csv" -Force if($SfbOnline){ $ranges = @() foreach($item in $numberBlocks){ $start = "tel:" + ($item -split ",")[0] $end = "tel:" + ($item -split ",")[1] $myObject1 = New-Object System.Object $myObject1 | Add-Member -type NoteProperty -name "NumberRangeStart" -Value $start $myObject1 | Add-Member -type NoteProperty -name "NumberRangeEnd" -Value $end $ranges += $myObject1 } }else{ $ranges = Get-CsUnassignedNumber } $latest = Get-ChildItem -Path $outputDir -filter "*.csv" | Sort-Object LastAccessTime -Descending | Select-Object -First 1 $assignedNumbers = Import-Csv -LiteralPath $latest.VersionInfo.FileName $result = "Range,RangeStart,RangeEnd,AvailableNumber" foreach($range in $ranges){ $start = [long]$range.NumberRangeStart.Substring(5,11) $end = [long]$range.NumberRangeEnd.Substring(5,11) #reduce to a +41 number in case the range has been put in as +99 if($start -gt 98999999999){$start = $start - $reduce} if($end -gt 98999999999){$end = $end - $reduce} $available = @() $x = $start while($x -le $end){ if($x -notin $assignedNumbers.DDI){ $available += $x } $x = $x + 1 } foreach($item in $available){ $result += [environment]::NewLine $result += "$($range.Identity),$start,$end,$item" } #add the ranges even if they don't have free numbers for the excel script output. $result += [environment]::NewLine $result += "$($range.Identity),$start,$end" } $result | Out-File -FilePath "$outputDir\Available-numbers.csv" -Encoding unicode } |