Powershell script to find out Teams policies by users

%3CLINGO-SUB%20id%3D%22lingo-sub-1210021%22%20slang%3D%22en-US%22%3EPowershell%20script%20to%20find%20out%20Teams%20policies%20by%20users%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1210021%22%20slang%3D%22en-US%22%3E%3CP%3EHey%20everyone%2C%20do%20you%20know%20if%20there%20is%20a%20way%20to%20run%20a%20script%20to%20find%20what%20Teams%20policies%20are%20assigned%20to%20what%20user%3F%20%26nbsp%3BWe%20have%20a%20private%20channel%20policy%20in%20place-%20I%20would%20like%20to%20find%20out%20a%20list%20of%20users%20that%20policy%20is%20assigned%20to.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20if%20you%20delete%20a%20user%20from%20a%20custom%20policy%20does%20that%20user%20get%20the%20default%20policy%3F%20%26nbsp%3BThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1210021%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdministrator%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epolicies%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20shell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETeams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1213946%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20find%20out%20Teams%20policies%20by%20users%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1213946%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F185103%22%20target%3D%22_blank%22%3E%40Ethan%20Stern%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETake%20a%20look%20here%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fteams%2Fget-csuserpolicyassignment%3Fview%3Dteams-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fteams%2Fget-csuserpolicyassignment%3Fview%3Dteams-ps%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20it%20helps%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGraham%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2180072%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20find%20out%20Teams%20policies%20by%20users%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2180072%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F185103%22%20target%3D%22_blank%22%3E%40Ethan%20Stern%3C%2FA%3E%26nbsp%3BI%20wrote%20a%20quick%20query%20for%20this%20information.%20%26nbsp%3BI%20was%20surprised%20there%20were%20not%20any%20examples.%20%26nbsp%3BYou%20can%20add%20additional%20elements%20if%20needed.%20%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24TeamsUsers%20%3D%20Get-CsOnlineUser%20%7C%20Select-Object%20DisplayName%2CObjectId%2CUserPrincipalName%2C%20%60%0A%20%20%20%20SipAddress%2CEnabled%2CWindowsEmailAddress%2CLineURI%2CHostedVoiceMail%2COnPremEnterpriseVoiceEnabled%2COnPremLineURI%2CSipProxyAddress%2C%20%60%0A%20%20%20%20OnlineDialinConferencingPolicy%2CTeamsUpgradeEffectiveMode%2CTeamsUpgradePolicy%2CHostingProvider%0A%0A%24TeamsReport%20%3D%20%40()%0A%0AForeach%20(%24User%20in%20%24TeamsUsers)%20%7B%0A%20%20%20%20%24Info%20%3D%20%22%22%20%7C%20Select%20%22DisplayName%22%2C%22ObjectId%22%2C%22UserPrincipalName%22%2C%22SipAddress%22%2C%22Enabled%22%2C%22LineURI%22%2C%20%60%0A%20%20%20%20%22WindowsEmailAddress%22%2C%22HostedVoiceMail%22%2C%22OnPremEnterpriseVoiceEnabled%22%2C%22OnPremLineURI%22%2C%22SipProxyAddress%22%2C%20%60%0A%20%20%20%20%22OnlineDialinConferencingPolicy%22%2C%22TeamsUpgradeEffectiveMode%22%2C%22TeamsUpgradePolicy%22%2C%22HostingProvider%22%2C%20%60%0A%20%20%20%20%22VoicePolicy%22%2C%22MeetingPolicy%22%2C%22TeamsMeetingPolicy%22%2C%22TeamsMessagingPolicy%22%2C%22TeamsAppSetupPolicy%22%2C%20%60%0A%20%20%20%20%22TeamsCallingPolicy%22%2C%22VoicePolicySource%22%2C%22MeetingPolicySource%22%2C%22TeamsMeetingPolicySource%22%2C%20%60%0A%20%20%20%20%22TeamsMessagingPolicySource%22%2C%22TeamsAppSetupPolicySource%22%2C%22TeamsCallingPolicySource%22%0A%0A%20%20%20%20Write-Host%20%22Querying%20policy%20information%20for%22%20%24User.DisplayName%20-ForegroundColor%20Green%0A%0A%20%20%20%20%24UserPolicies%20%3D%20Get-CsUserPolicyAssignment%20-Identity%20%24User.ObjectId%0A%0A%20%20%20%20%24Info.DisplayName%20%3D%20%24User.DisplayName%0A%20%24Info.ObjectId%20%3D%20%24User.ObjectId%0A%20%24Info.UserPrincipalName%20%3D%20%24User.UserPrincipalName%0A%20%24Info.SipAddress%20%3D%20%24User.SipAddress%0A%20%24Info.Enabled%20%3D%20%24User.Enabled%0A%20%24Info.LineURI%20%3D%20%24User.LineURI%0A%20%24Info.WindowsEmailAddress%20%3D%20%24User.WindowsEmailAddress%0A%20%24Info.HostedVoiceMail%20%3D%20%24User.HostedVoiceMail%0A%20%24Info.OnPremEnterpriseVoiceEnabled%20%3D%20%24User.OnPremEnterpriseVoiceEnabled%0A%20%24Info.OnPremLineURI%20%3D%20%24User.OnPremLineURI%0A%20%24Info.SipProxyAddress%20%3D%20%24User.SipProxyAddress%0A%20%24Info.OnlineDialinConferencingPolicy%20%3D%20%24User.OnlineDialinConferencingPolicy%0A%20%24Info.TeamsUpgradeEffectiveMode%20%3D%20%24User.TeamsUpgradeEffectiveMode%0A%20%24Info.TeamsUpgradePolicy%20%3D%20%24User.TeamsUpgradePolicy%0A%20%24Info.HostingProvider%20%3D%20%24User.HostingProvider%0A%20%20%20%20%24Info.VoicePolicy%20%3D%20(%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22VoicePolicy%22%7D).PolicyName%0A%20%20%20%20%24Info.VoicePolicy%20%3D%20((%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22VoicePolicy%22%7D).PolicySource).AssignmentType%0A%20%20%20%20%24Info.MeetingPolicy%20%3D%20(%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22MeetingPolicy%22%7D).PolicyName%0A%20%20%20%20%24Info.MeetingPolicySource%20%3D%20((%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22MeetingPolicy%22%7D).PolicySource).AssignmentType%0A%20%20%20%20%24Info.TeamsMeetingPolicy%20%3D%20(%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsMeetingPolicy%22%7D).PolicyName%0A%20%20%20%20%24Info.TeamsMeetingPolicySource%20%3D%20((%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsMeetingPolicy%22%7D).PolicySource).AssignmentType%0A%20%20%20%20%24Info.TeamsMessagingPolicy%20%3D%20(%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsMessagingPolicy%22%7D).PolicyName%0A%20%20%20%20%24Info.TeamsMessagingPolicySource%20%3D%20((%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsMessagingPolicy%22%7D).PolicySource).AssignmentType%0A%20%20%20%20%24Info.TeamsAppSetupPolicy%20%3D%20(%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsAppSetupPolicy%22%7D).PolicyName%0A%20%20%20%20%24Info.TeamsAppSetupPolicySource%20%3D%20((%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsAppSetupPolicy%22%7D).PolicySource).AssignmentType%0A%20%20%20%20%24Info.TeamsCallingPolicy%20%3D%20(%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsCallingPolicy%22%7D).PolicyName%0A%20%20%20%20%24Info.TeamsCallingPolicySource%20%3D%20((%24UserPolicies%20%7C%20Where-Object%20%7B%24_.PolicyType%20-eq%20%22TeamsCallingPolicy%22%7D).PolicySource).AssignmentType%0A%0A%20%20%20%20%24TeamsReport%20%2B%3D%20%24Info%0A%20%20%20%20%24Info%20%3D%20%24null%0A%20%20%20%20%7D%0A%0A%24TeamsReport%20%7C%20Export-Csv%20.%5CTeamsReport.csv%20-NoTypeInformation%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2256817%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20to%20find%20out%20Teams%20policies%20by%20users%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2256817%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F185103%22%20target%3D%22_blank%22%3E%40Ethan%20Stern%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20to%20let%20you%20know%2C%20works%20without%20code%20as%20well%20by%20using%20the%20filter%20option%20(click%20on%20%22Users%22%20in%20the%20left%20navigation%20then%20on%20the%20filter%20symbol%20and%20add%20the%20condition).%26nbsp%3B%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fadmin.teams.microsoft.com%2Fusers%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fadmin.teams.microsoft.com%2Fusers%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Timon-O_0-1617725256842.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F270504i62A4D875767EAEC2%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Timon-O_0-1617725256842.png%22%20alt%3D%22Timon-O_0-1617725256842.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E(screenshot%20as%20an%20example)%3C%2FP%3E%3CP%3EI%20hope%20it%20helps.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

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!

3 Replies

@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

 

@Ethan Stern 

 

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

Timon-O_0-1617725256842.png
(screenshot as an example)

I hope it helps.