Forum Discussion
I want to change auto aftandend number using powershell
- Feb 03, 2025
Hi danikoershuis,
You detached the Variables, so nothing is written back to the $AA VariableConnect-MicrosoftTeams #Get AutoAttendand $AA = Get-CsAutoAttendant -NameFilter AutoAttendantDemo01 $AA.CallFlows | where {$_.Name -eq "AutoAttendantDemo01 After hours call flow"} $Menu = ($aa.CallFlows | where {$_.Name -eq "AutoAttendantDemo01 After hours call flow"}).Menu $Menu.MenuOptions #Create a new Target $CallTarget = New-CsAutoAttendantCallableEntity -Identity "tel:+1234567890" -Type ExternalPSTN $menuOption = New-CsAutoAttendantMenuOption -Action TransferCallToTarget -DtmfResponse Automatic -CallTarget $CallTarget #Figure out witch is the After hours call flow -> In my case it's the first Entry in the Array [0] $aa.CallFlows[0] $aa.CallFlows[0].Menu.MenuOptions #Set ne new Menu Option with the new Target to the $AA Object $aa.CallFlows[0].Menu.MenuOptions = $menuOption #Update the Autoattendant Set-CsAutoAttendant -Instance $AA
Kind Regards
Andres
Hello Andres,
I made this script using your blog.
But it still does not work could you maby have a look if you can see if i did something wrong?
# Connect with teams
Connect-MicrosoftTeams
# Setting up variables
$AutoAttendantId = "3d7ff2b0-1b1e-4bd8-92c3-cb4e3316d6be"
$NewPhoneNumber = "+31612345678"
# Get autoattendant
$AA = Get-CsAutoAttendant -Identity $AutoAttendantId
if (-not $AA) {
Write-Host "Auto Attendant not found. Please check the ID." -ForegroundColor Red
Exit
}
# Go to after hours
$AfterHoursCallFlow = $AA.CallFlows | Where-Object { $_.Name -like "*After hours*" }
if (-not $AfterHoursCallFlow) {
Write-Host "After Hours Call Flow not found. Please check the settings." -ForegroundColor Red
Exit
}
# Go to the menu to change the phone number
$AfterHoursCallFlow.CallRouting | ForEach-Object {
if ($_.Type -eq "PhoneNumber") {
$_.PhoneNumber = $NewPhoneNumber
}
}
# Update the auto attendant
Set-CsAutoAttendant -Instance $AA
Write-Host "Phone number updated successfully to $NewPhoneNumber" -ForegroundColor Green
Hi danikoershuis,
You detached the Variables, so nothing is written back to the $AA Variable
Connect-MicrosoftTeams
#Get AutoAttendand
$AA = Get-CsAutoAttendant -NameFilter AutoAttendantDemo01
$AA.CallFlows | where {$_.Name -eq "AutoAttendantDemo01 After hours call flow"}
$Menu = ($aa.CallFlows | where {$_.Name -eq "AutoAttendantDemo01 After hours call flow"}).Menu
$Menu.MenuOptions
#Create a new Target
$CallTarget = New-CsAutoAttendantCallableEntity -Identity "tel:+1234567890" -Type ExternalPSTN
$menuOption = New-CsAutoAttendantMenuOption -Action TransferCallToTarget -DtmfResponse Automatic -CallTarget $CallTarget
#Figure out witch is the After hours call flow -> In my case it's the first Entry in the Array [0]
$aa.CallFlows[0]
$aa.CallFlows[0].Menu.MenuOptions
#Set ne new Menu Option with the new Target to the $AA Object
$aa.CallFlows[0].Menu.MenuOptions = $menuOption
#Update the Autoattendant
Set-CsAutoAttendant -Instance $AA
Kind Regards
Andres