Mar 04 2020 01:46 PM
Hey everyone, do you know if there is a way to run a script to find what Teams policies are assigned to what user? We have a private channel policy in place- I would like to find out a list of users that policy is assigned to.
Also, if you delete a user from a custom policy does that user get the default policy? Thanks!
Mar 06 2020 09:03 AM
Hi @Ethan Stern,
Take a look here: https://docs.microsoft.com/en-us/powershell/module/teams/get-csuserpolicyassignment?view=teams-ps
Hope it helps,
Graham
Mar 02 2021 03:01 PM
@Ethan Stern I wrote a quick query for this information. I was surprised there were not any examples. You can add additional elements if needed.
$TeamsUsers = Get-CsOnlineUser | Select-Object DisplayName,ObjectId,UserPrincipalName, `
SipAddress,Enabled,WindowsEmailAddress,LineURI,HostedVoiceMail,OnPremEnterpriseVoiceEnabled,OnPremLineURI,SipProxyAddress, `
OnlineDialinConferencingPolicy,TeamsUpgradeEffectiveMode,TeamsUpgradePolicy,HostingProvider
$TeamsReport = @()
Foreach ($User in $TeamsUsers) {
$Info = "" | Select "DisplayName","ObjectId","UserPrincipalName","SipAddress","Enabled","LineURI", `
"WindowsEmailAddress","HostedVoiceMail","OnPremEnterpriseVoiceEnabled","OnPremLineURI","SipProxyAddress", `
"OnlineDialinConferencingPolicy","TeamsUpgradeEffectiveMode","TeamsUpgradePolicy","HostingProvider", `
"VoicePolicy","MeetingPolicy","TeamsMeetingPolicy","TeamsMessagingPolicy","TeamsAppSetupPolicy", `
"TeamsCallingPolicy","VoicePolicySource","MeetingPolicySource","TeamsMeetingPolicySource", `
"TeamsMessagingPolicySource","TeamsAppSetupPolicySource","TeamsCallingPolicySource"
Write-Host "Querying policy information for" $User.DisplayName -ForegroundColor Green
$UserPolicies = Get-CsUserPolicyAssignment -Identity $User.ObjectId
$Info.DisplayName = $User.DisplayName
$Info.ObjectId = $User.ObjectId
$Info.UserPrincipalName = $User.UserPrincipalName
$Info.SipAddress = $User.SipAddress
$Info.Enabled = $User.Enabled
$Info.LineURI = $User.LineURI
$Info.WindowsEmailAddress = $User.WindowsEmailAddress
$Info.HostedVoiceMail = $User.HostedVoiceMail
$Info.OnPremEnterpriseVoiceEnabled = $User.OnPremEnterpriseVoiceEnabled
$Info.OnPremLineURI = $User.OnPremLineURI
$Info.SipProxyAddress = $User.SipProxyAddress
$Info.OnlineDialinConferencingPolicy = $User.OnlineDialinConferencingPolicy
$Info.TeamsUpgradeEffectiveMode = $User.TeamsUpgradeEffectiveMode
$Info.TeamsUpgradePolicy = $User.TeamsUpgradePolicy
$Info.HostingProvider = $User.HostingProvider
$Info.VoicePolicy = ($UserPolicies | Where-Object {$_.PolicyType -eq "VoicePolicy"}).PolicyName
$Info.VoicePolicy = (($UserPolicies | Where-Object {$_.PolicyType -eq "VoicePolicy"}).PolicySource).AssignmentType
$Info.MeetingPolicy = ($UserPolicies | Where-Object {$_.PolicyType -eq "MeetingPolicy"}).PolicyName
$Info.MeetingPolicySource = (($UserPolicies | Where-Object {$_.PolicyType -eq "MeetingPolicy"}).PolicySource).AssignmentType
$Info.TeamsMeetingPolicy = ($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsMeetingPolicy"}).PolicyName
$Info.TeamsMeetingPolicySource = (($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsMeetingPolicy"}).PolicySource).AssignmentType
$Info.TeamsMessagingPolicy = ($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsMessagingPolicy"}).PolicyName
$Info.TeamsMessagingPolicySource = (($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsMessagingPolicy"}).PolicySource).AssignmentType
$Info.TeamsAppSetupPolicy = ($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsAppSetupPolicy"}).PolicyName
$Info.TeamsAppSetupPolicySource = (($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsAppSetupPolicy"}).PolicySource).AssignmentType
$Info.TeamsCallingPolicy = ($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsCallingPolicy"}).PolicyName
$Info.TeamsCallingPolicySource = (($UserPolicies | Where-Object {$_.PolicyType -eq "TeamsCallingPolicy"}).PolicySource).AssignmentType
$TeamsReport += $Info
$Info = $null
}
$TeamsReport | Export-Csv .\TeamsReport.csv -NoTypeInformation
Apr 06 2021 09:12 AM
Just to let you know, works without code as well by using the filter option (click on "Users" in the left navigation then on the filter symbol and add the condition).
https://admin.teams.microsoft.com/users
(screenshot as an example)
I hope it helps.
Jul 12 2021 06:42 AM
@JohnLockett.... great piece of code!
Jul 16 2021 10:50 AM
Jul 19 2021 12:45 AM
Jul 19 2021 02:07 AM
Jul 19 2021 02:42 AM
@SanatKMahapatra wow that a long time. depending on what information you want to return in the excel you could limit the $Info = "" | Select to reduce the content that is returned?
I need to limit my next run by office/location but I haven't had the time to rework the PS yet to do that. But looking quickly you could add a | where {$_.CountryOrRegionDisplayName -eq "xxxx"} to the end of the $TeamsUsers = Get-CsOnlineUser | Select-Object section. That might work or use the CountryAbbreviation property instead.
Jul 19 2021 01:59 PM
Yes, you can update the top of the script to use a filter and select the attributes you want to filter on. I would suggest you query some of your users and verify that the Teams PS Module sees those attributes before trying it. For example:
Get-CsOnlineUser -Filter {CountryAbbreviation -eq "US"}
OR
Get-CsOnlineUser -Filter {City -eq "Phoenix"}
OR
Get-CsOnlineUser -Filter {(City -eq "Dallas") -or (City -eq "Phoenix")}
Jul 19 2021 11:39 PM
Sep 27 2021 12:58 AM
Oct 18 2021 01:41 AM
Feb 21 2023 12:52 AM
Get-CsUserPolicyAssignment : Cannot bind argument to parameter 'Identity' because it is an empty string.
At C:\PSScripts\teams_assigned-policies.ps1:17 char:58
+ ... $UserPolicies = Get-CsUserPolicyAssignment -Identity $User.ObjectId
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-CsUserPolicyAssignment], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Get-CsUserPolicyAssignment
Also no data is presented in csv at all for any user (all users have the policies assigned by group membership)
Mar 08 2023 01:43 PM
Late to the party but I've created a powershell function to show the order of policies (global, direct and groups if appropriate)
jchr-msft/TeamsAdmin (github.com)
Its not the fastest in the world, but it does the job
Mar 10 2023 08:07 AM
Mar 10 2023 08:27 AM