Created
July 19, 2024 15:12
-
-
Save cicero343/a3b6e46f01a8d71b7c41af30f92c081e to your computer and use it in GitHub Desktop.
Export CSV file of all assigned MS Teams phone numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect to Microsoft Teams PowerShell module | |
Import-Module MicrosoftTeams | |
# Connect to Microsoft Teams | |
Connect-MicrosoftTeams | |
# Get a list of all the users who currently have Teams phone numbers assigned | |
$phoneNumber = Get-csonlineuser | where-object { $_.LineURI -notlike $null } | select UserPrincipalName, LineURI | |
# Create a CSV file with these phone numbers | |
$csvPath = "/Users/test/FileNameHere.csv" | |
$phoneNumber | Export-Csv -Path $csvPath -NoTypeInformation | |
# Read the CSV file | |
$csvData = Import-csv -path $csvPath | |
# Update the column names in the first row | |
try { | |
# Read the CSV file as a string | |
$csvContent = Get-Content -Path $csvPath -Raw | |
# Replace the words "UserPrincipalName" and "LineURI" with "userPrincipalName" and "telephoneNumber" | |
$updatedContent = $csvContent -replace "UserPrincipalName", "userPrincipalName" -replace "LineURI", "telephoneNumber" | |
# Overwrite the original CSV file with the updated content | |
$updatedContent | Set-Content -Path $csvPath | |
} | |
catch { | |
Write-Host "An error occurred: $_" | |
} | |
# Save the updated CSV file | |
$csvData = Export-Csv -path "/Users/test/FileNameHere.csv" -NoTypeInformation -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment