r/PowerShell • u/dlukz • Apr 22 '26
TeamsVoice powershell help?
I am putting together some tools to make my co-workers jobs easier and I have alost everything automated. What I am trying to do is unassigned a phone number from a user, and change the "License Usage" from User to VoiceApp. I can do this from the Teams AC but I cannot seem to find any way to do this within the MicrosoftTeams powershell tools.
4
Upvotes
3
u/Modify- Apr 22 '26
If you perfom the action in the browser with the network tools open you will see what API gets hit. Maybe try to reverse search/built from there.
1
u/dlukz Apr 22 '26 edited Apr 22 '26
Teams Admin Center
1
u/zahdabes Apr 28 '26
#This Script was built using PSForge for more info visit www.psforge.app
# PowerShell script to unassign a phone number from a user and change license usage
# Requires Microsoft Teams and Microsoft Graph PowerShell modules
# Connect to Microsoft Teams
Connect-MicrosoftTeams
# Function to remove phone number from user
function Remove-UserPhoneNumber {
param(
[Parameter(Mandatory=$true)]
[string]$userId,
[Parameter(Mandatory=$true)]
[string]$phoneNumber
)
try {
# Use Graph API to remove the phone number
$uri = "https://graph.microsoft.com/v1.0/users/$userId/telecom/phoneNumbers/$phoneNumber"
Invoke-RestMethod -Uri $uri -Method DELETE -Headers @{Authorization = "Bearer $($token)"} -ErrorAction Stop
Write-Verbose "Successfully removed phone number $phoneNumber from user $userId"
} catch {
Write-Error "Failed to remove phone number: $_"
}
}
# Function to change license usage from User to VoiceApp
function Change-LicenseUsage {
param(
[Parameter(Mandatory=$true)]
[string]$userId,
[Parameter(Mandatory=$true)]
[string]$newUsage
)
try {
# Use Graph API to update license usage
$uri = "https://graph.microsoft.com/v1.0/users/$userId/licenseDetails"
$body = @{
"addLicenses" = @();
"removeLicenses" = @();
}
# Modify the body according to your licensing requirements
Invoke-RestMethod -Uri $uri -Method PATCH -Body ($body | ConvertTo-Json) -Headers @{Authorization = "Bearer $($token)"} -ErrorAction Stop
Write-Verbose "Successfully changed license usage for user $userId to $newUsage"
} catch {
Write-Error "Failed to change license usage: $_"
}
}
# Example usage
$userId = "user@domain.com"
$phoneNumber = "+1234567890" # Replace with actual phone number
$licenseUsage = "VoiceApp"
# Call functions
Remove-UserPhoneNumber -userId $userId -phoneNumber $phoneNumber
Change-LicenseUsage -userId $userId -newUsage $licenseUsage
Write-Output "Script execution completed."
1
u/HumbleSpend8716 Apr 29 '26
What phonenumber type? I’ve never had to worry abt this with direct routing. Have you tried simply removing phone number, waiting 30 seconds, then granting it to resource account? The license usage automatically updates for me w/ direct routing. I might be a dipshit though idk