Forum Discussion
I want to change auto aftandend number using powershell
Hello,
i want to create a powershell script where i can change the Auto attendant of the teams admin so that users can change the phone number of the after hours without having a teams admin license, does anyone know how i can change the number of the Auto attendants using powershell?
Its in Auto attendants -> your Auto attendant -> Call flow for after hours -> Call routing options - > redirect call -> phone number that i want to change using powershell.
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
8 Replies
- danikoershuisCopper Contributor
Hello Luchete,
Thank you i made a quick script but it does not work, maby you could take a look if i messed something up.# connect with teams
Connect-MicrosoftTeams
# Set up variable
$AutoAttendantId = "3d7ff2b0-1b1e-4bd8-92c3-cb4e3316d6be"
$NewPhoneNumber = "+31625450875"
# Get auto attendant
$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 menu screen of phone number
$AfterHoursCallFlow.CallRouting | ForEach-Object {
if ($_.Type -eq "PhoneNumber") {
$_.PhoneNumber = $NewPhoneNumber
}
}
# Update de Auto Attendant with new settings
Set-CsAutoAttendant -Instance $AA
# Show tekst that its completedWrite-Host "Phone number updated successfully to $NewPhoneNumber" -ForegroundColor Green
- Andres-BohrenIron Contributor
I can only point to the right direction
Connect-MicrosoftTeams $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
Have also a look herehttps://blog.icewolf.ch/archive/2021/01/30/create-teams-auto-attendant-and-call-queue-with-powershell/
Kind Regards
Andres Bohren- danikoershuisCopper Contributor
Hello Andres
I made a script based on your blog but it still does not work could you take a look if i did something wrong?# connect with teams
Connect-MicrosoftTeams
# Set up variable
$AutoAttendantId = "3d7ff2b0-1b1e-4bd8-92c3-cb4e3316d6be"
$NewPhoneNumber = "+31625450875"
# Get auto attendant
$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 menu screen of phone number
$AfterHoursCallFlow.CallRouting | ForEach-Object {
if ($_.Type -eq "PhoneNumber") {
$_.PhoneNumber = $NewPhoneNumber
}
}
# Update de Auto Attendant with new settings
Set-CsAutoAttendant -Instance $AA
# Show tekst that its completedWrite-Host "Phone number updated successfully to $NewPhoneNumber" -ForegroundColor Green
- danikoershuisCopper Contributor
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
- Andres-BohrenIron Contributor
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
- leonjackee6Copper Contributor
You can use the Set-Cs Auto Attendant cmdlet in PowerShell to modify the settings for the Auto Attendant, including the after-hours phone number. Just make sure to specify the correct Auto Attendant of and use the appropriate parameters for call routing options.
- danikoershuisCopper Contributor
Hi Leonjackee6,
That is how far ive gotten before going on here the problem is i get into the auto attendent with cmdlet powershell but i cant change the number cause every command that i find or try its not availible. so if you have the correct one i would love to hear it.
- lucheteIron Contributor
Hi danikoershuis!
On PowerShell you can change the auto attendant settings by using the Teams PowerShell module. To modify the after-hours phone number, you’ll need to first connect to the Teams PowerShell module and then use the Set-CsAutoAttendant cmdlet. You can specify the after-hours settings and update the phone number with the AfterHoursCallRouting option. Make sure you have the correct permissions, and that you're working with a Teams admin account or have the required privileges for the task, otherwise you wont be able to do it. If you don't have access to the full Teams admin license, you might need to adjust permissions or roles in your tenant.
Hope it helps!