Skip to content

Instantly share code, notes, and snippets.

@shanehoey
Last active May 23, 2022 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanehoey/f6ccfdd3c90c8f7d3d4e986defd902ff to your computer and use it in GitHub Desktop.
Save shanehoey/f6ccfdd3c90c8f7d3d4e986defd902ff to your computer and use it in GitHub Desktop.
Direct Routing Audit

Direct Routing Auditing Examples

The following powershell scripts will export your direct routing configuration for auditing purposes. once you have the clixml files you can use them to compare at a later date

  • Assumes version 4.3.0 or higher of Microsoft Teams Module
  • Assumes that all properties are exported to clixml file

Audit Users

  • users-all.ps1 - Export All Users in Tenant - Not recommended on large tenants

  • users-list.ps1 - Export Users based on list of users manually defined

  • users-csv.ps1 - Export Users based on input from csv file

  • users.csv - Sample Users.csv if you want to audit only subset of users

Audit Direct Routing

# Display
Get-CsOnlinePSTNGateway | Select-Object * | Format-list
Get-CsOnlinePstnUsage | Select-Object * | Format-list
Get-CsOnlineVoiceRoute | Select-Object * | Format-list
Get-CsOnlineVoiceRoutingPolicy| Select-Object * | Format-list
Get-CsVoiceRoutingPolicy | Select-Object * | Format-list
Get-CsTenantDialPlan | Select-Object * | Format-list
# Export to CLIXML
Get-CsOnlinePSTNGateway | Export-clixml -path _CsOnlinePSTNGateway.clixml
Get-CsOnlinePstnUsage | Export-clixml -path _CsOnlinePstnUsage.clixml
Get-CsOnlineVoiceRoute | Export-clixml -path _CsOnlineVoiceRoute.clixml
Get-CsonlineVoiceRoutingPolicy| Export-clixml -path _CsonlineVoiceRoutingPolicy.clixml
Get-CsVoiceRoutingPolicy | Export-clixml -path _CsVoiceRoutingPolicy.clixml
Get-CsTenantDialPlan | Export-clixml -path _CsTenantDialPlan.clixml
# Connect to Teams
set-location c:\fae\ #update if required
connect-microsoftteams
# Get all users
$users = Get-CsOnlineUser
# Display all users to screen
$users | Select-Object userprincipalname, sipaddress ,alias, DisplayName, UsageLocation, Tenantdialplan, Dialplan, TeamsUpgradeEffectiveMode, LineUri, accountenabled , EnterpriseVoiceEnabled, FeatureTypes, assignedplan, ProvisionedPlan, IsSipEnabled, InterpretedUserType, hostingprovider, CallingLineIdentity,Teams*
$users | select-object sipaddress,UsageLocation,IsSipEnabled,accountenabled,TeamsUpgradeEffectiveMode, LineUri , EnterpriseVoiceEnabled,
# Export All Users to clixml file (including all properties)
$users | export-clixml -path users-all.clixml
# update the following items if required
$folder = "c:\fae\"
$inputfile = "users.csv"
# Connect to Teams
set-location -path $folder
connect-microsoftteams
# To check a subset of users from $inputfile (above)
$users = import-csv $inputfile
# To check import successful
$users.count
$users.sipaddress
# Audit all the users
$OnlineUsers = for($i=1 ; $i -lt $users.count; $i++) {
Write-verbose -Message "Checking User $($users[$i].sipaddress) - $($i) of $($users.count)" -Verbose
Get-CsOnlineUser -identity $users[$i].sipaddress
}
$OnlineUsersMinProp = $OnlineUsers | Select-Object userprincipalname, sipaddress ,alias, DisplayName, UsageLocation, Tenantdialplan, Dialplan, TeamsUpgradeEffectiveMode, LineUri, accountenabled , EnterpriseVoiceEnabled, IsSipEnabled, InterpretedUserType, hostingprovider
# To export minimum properties to screen
$OnlineUsersMinProp | Format-list *
# To export all properties to screen
$OnlineUsers | Format-list *
# To export minimum properties to clixml file
$OnlineUsersMinProp | Export-clixml -Path users-csv-minprop.clixml
# To export all properties to clixml file
$OnlineUsers | Export-clixml -Path users-csv.clixml
# To export minimum properties to csv file
$OnlineUsersMinProp | convertto-csv | out-file -Path users-csv-minprop.csv
# To export all properties to csv file
$OnlineUsers | convertto-csv | out-file -Path users-csv.csv
### Below requires Powershell-Yaml installed ###
# To export minimum properties to csv file
$usersminimum | convertto-yaml | out-file -Path users-csv-minprop.yaml
# To export all properties to csv file
$users | convertto-yaml | out-file -Path users-csv.yaml
# To export minimum properties to csv file
$usersminimum | convertto-json | out-file -Path users-csv-minprop.json
# To export all properties to csv file
$users | convertto-json | out-file -Path users-csv.json
# To manually check a subset of users based on username/alias/sipaddress
$users = "AdeleV","AlexW","AllanD","ChristieC","DebraB","DiegoS","GradyA","IrvinS","IsaiahL","JohannaL","JoniS","LeeG","LidiaH","LynneR","MeganB","MiriamG","NestorW","PattiF","PradeepG"
$teamusers = for($i=1 ; $i -lt $users.count; $i++) {
Write-verbose -Message "Checking User $($users[$i]) - $($i) of $($users.count)" -Verbose
Get-CsOnlineUser -identity $user | Select-Object userprincipalname, sipaddress ,alias, DisplayName, UsageLocation, Tenantdialplan, Dialplan, TeamsUpgradeEffectiveMode, LineUri, accountenabled , EnterpriseVoiceEnabled, FeatureTypes, assignedplan, ProvisionedPlan, IsSipEnabled, InterpretedUserType, hostingprovider
}
# to display on screen
$teamusers | Format-list *
# to export to file clixml
$teamusers | Export-clixml -Path teamusers.clixml
# to export to file csv
$teamusers | convertto-csv | out-file -Path teamusers.csv
SiteID Alias SipAddress UserPrincipalName onlinevoiceroutingpolicy phonenumber onlineDialOutPolicy tenantDialPlan
AdeleV
AlexW
AllanD
ChristieC
DebraB
DiegoS
GradyA
IrvinS
IsaiahL
JohannaL
JoniS
LeeG
LidiaH
LynneR
MeganB
MiriamG
NestorW
PattiF
PradeepG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment