param( [Parameter(Mandatory=$true)] [ValidateSet("Export","Create-Auto-Attendents","Create-CS-EXUMContacts")][switch] $Mode, [Parameter(Mandatory=$true)] [string] $AudioFilePath, [Parameter(Mandatory=$true)] [string] $LogFile ) #Make sure you connect to Exchange first in Powershell #You also need the SfB Admin Tools installed #Yes, I know, there is no error handling, this was quick and dirty. #If the last character in the path is a \ then delete it if ($AudioFIlePath.Substring($AudioFIlePath.Length-1) -like "\") { $AudioFIlePath = $AudioFIlePath.Substring(0,$AudioFIlePath.Length-1) } #Create the Directory if (-not (test-path $AudioFIlePath)) { new-item -ItemType Directory -Path $AudioFIlePath } $mode #If the file exists if ( ( ($mode -notlike "Export") -eq $false) -and ((Test-Path -PathType Any -IsValid $LogFile) -eq $true ) ) { $Continue = Read-Host "File Exists, Press D to delete it and continue, any other key to quit" if ($Continue -like "D") { try {remove-item $LogFile -Force -ErrorAction STOP} catch { Write-host "Could not delete file, perhaps it is open, exiting" Break } } else {Break} } Switch ($Mode) { #Export the Data "Report" { $plans = @() $plans += New-Object -TypeName psobject -Property @{Filepath ="";AAName="";Dialplan="";phonenumber="";NewAAName="";NewDialPlan="";E164="";DID="";NewAA="";SIPAddress="";OU="";sfbpool=""} foreach ($dialplan in Get-UMDialPlan) { foreach ($aa in Get-UMAutoAttendant -UMDialPlan $dialplan.Identity) { $aa.BusinessHoursWelcomeGreetingFilename $plans += New-Object -TypeName psobject -Property @{Filepath=$($AudioFIlePath+"\"+$aa.BusinessHoursWelcomeGreetingFilename);AAName=$aa.Id;Dialplan=$dialplan.Identity;phonenumber=$aa.PilotIdentifierList} $Prompt = Export-UMPrompt -PromptFileName $aa.BusinessHoursWelcomeGreetingFilename -UMAutoAttendant $aa.Identity Set-Content -path $($AudioFIlePath+"\"+$aa.BusinessHoursWelcomeGreetingFilename) -Value $prompt.AudioData -Encoding Byte -Force } } $plans | export-csv $LogFile -NoTypeInformation } #End Report #Create the AutoAttendants "Create-Auto-Attendents" { foreach ($line in import-csv $LogFile ) { $oldAA = Get-UMAutoAttendant -Identity $line.AAName $FileName = (get-item $line.Filepath).name $line.newAAName New-UMAutoAttendant -Name $line.NewAAName -PilotIdentifierList $("+"+$line.DID) -UMDialPlan $line.NEwDialPlan Set-UMAutoAttendant -Identity $line.NewAAName -BusinessHoursSchedule $oldAA.BusinessHoursSchedule -AfterHoursMainMenuCustomPromptEnabled $([bool]$oldADD.AfterHoursMainMenuCustomPromptEnabled) -TimeZoneName $oldAA.TimeZoneName -AllowExtensions $oldAA.AllowExtensions -SpeechEnabled $oldAA.SpeechEnabled -OperatorExtension $oldAA.OperatorExtension -SendVoiceMsgEnabled $oldAA.SendVoiceMsgEnabled -BusinessHoursTransferToOperatorEnabled $oldAA.BusinessHoursTransferToOperatorEnabled -MatchedNameSelectionMethod $oldAA.MatchedNameSelectionMethod -AfterHoursTransferToOperatorEnabled $oldAA.AfterHoursTransferToOperatorEnabled -BusinessLocation $oldAA.BusinessLocation -DTMFFallbackAutoAttendant $oldAA.DTMFFallbackAutoAttendant -InfoAnnouncementEnabled $oldAA.InfoAnnouncementEnabled -BusinessName $OldAA.BusinessName -ContactScope DialPlan -CallSomeoneEnabled $OldAA.CallSomeoneEnabled -Language $OldAA.Language -PilotIdentifierList $("+"+$line.DID) # Things that don't work -AfterHoursKeyMappingEnabled $oldAA.AfterHoursKeyMappingEnabled -AfterHoursKeyMapping $OldAA.AfterHoursKeyMapping -BusinessHoursKeyMappingEnabled $oldAA.BusinessHoursKeyMappingEnabled -BusinessHoursKeyMapping $oldAA.BusinessHoursKeyMapping -AllowDialPlanSubscribers:$true -NameLookupEnabled:$False if ( ($FileName -like "*.wav") -or ($fileName -like "*wma") ) { Set-UMAutoAttendant -Identity $line.NewAAName -BusinessHoursWelcomeGreetingFilename $FileName -BusinessHoursWelcomeGreetingEnabled:$True #-BusinessHoursMainMenuCustomPromptFilename $Oldaa.BusinessHoursMainMenuCustomPromptFilename -BusinessHoursMainMenuCustomPromptEnabled $oldAA.BusinessHoursMainMenuCustomPromptEnabled } Enable-UMAutoAttendant -Identity $line.NewAAName #Import the files [byte[]]$umfile = Get-content -Path $($line.Filepath) -Encoding Byte -ReadCount 0 Import-UMPrompt -UMAutoAttendant $line.NewAAName -PromptFileName $FileName -PromptFileData $umfile #> } #End Create-Auto-Attendents } #Create the CS-EXUMContact "Create-CS-EXUMContacts" { foreach ($line in import-csv $LogFile ) { $("+"+$line.DID) #Remove-CsExUmContact $line.SIPAddress -Confirm:$false if ($voicemailpolicy -like $null) { $vmpolocies = Get-CsHostedVoicemailPolicy | select Identity for ($i=0;$i -lt $vmpolocies.count; $i++) { $a = $i + 1 write-host $($a,$vmpolocies[$i].Identity) -Separator " " } $range = '(1-' + $vmpolocies.count + ')' $Select = Read-Host "Choose the correct VoiceMail Policy" $Range $Select = $Select -1 $voicemailpolicy = $vmpolocies[$select] } New-CsExUmContact -SipAddress $line.SIPAddress -RegistrarPool $line.sfbpool -OU $line.OU -AutoAttendant:$true -Description $line.NewAAName -DisplayNumber $("+"+$line.DID) -Confirm:$false Set-CsExUmContact -Identity $line.SIPAddress -EnterpriseVoiceEnabled:$true Grant-CsHostedVoicemailPolicy -PolicyName $voicemailpolicy -Identity $line.SIPAddress } #End Create-CS-EXUMContacts } }#End Switch