Microsoft Tech Community Live:  Microsoft Teams Edition
November 09, 2021, 08:00 AM - 12:00 PM (PST)

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%3CLINGO-SUB%20id%3D%22lingo-sub-2538370%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-2538370%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F984226%22%20target%3D%22_blank%22%3E%40JohnLockett%3C%2FA%3E....%20great%20piece%20of%20code!%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fhtml%2F%408341BD79091AF36AA2A09063B554B5CD%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2557052%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-2557052%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1018431%22%20target%3D%22_blank%22%3E%40Timon-O%3C%2FA%3E%3CBR%20%2F%3EPlease%20let%20me%20know%20how%20do%20you%20export%20the%20results%20to%20excel%20or%20CSV%20after%20applying%20the%20Filter%20on%20Teams%20Admin%20Center.%3CBR%20%2F%3ERegards%3CBR%20%2F%3ESanat%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2561217%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-2561217%22%20slang%3D%22en-US%22%3EHi%20Sanat%2C%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20don't%20there%20isn't%20an%20option%20in%20Teams%20Admin%20Center...%20thats%20why%20the%20about%20PowerShell%20is%20so%20useful.%3CBR%20%2F%3E%3CBR%20%2F%3ENote%20-%20some%20of%20the%20properties%20in%20the%20above%20PS%20are%20not%20exported%20so%20you%20may%20have%20to%20add%20on%20TeamsAppPermissionPolicy.%3CBR%20%2F%3E%3CBR%20%2F%3ERegards%2C%3CBR%20%2F%3E%3CBR%20%2F%3EDamian%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2561371%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-2561371%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F984226%22%20target%3D%22_blank%22%3E%40JohnLockett%3C%2FA%3E%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1101368%22%20target%3D%22_blank%22%3E%40Dlewis-79%3C%2FA%3E%20..%20Thank%20you%20for%20the%20details%20and%20confirmation%2C%20it's%20really%20helpful.%3CBR%20%2F%3EI%20have%20only%201%20query%2C%20It%20took%202.5%2B%20days%20and%20the%20query%20was%20still%20running%20which%20collected%20over%2038000%2B%20User%20objects%2C%20however%2C%20I%20had%20to%20cancel%20as%20it%20entered%20today%20production%20hours.%3CBR%20%2F%3EIs%20there%20any%20way%20to%20limit%20or%20place%20a%20condition%20like%20CountryCode%20or%20ExtensionAttribute%20or%20CustomAttribute%20to%20pull%20a%20more%20small%20and%20specific%20report.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2561429%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-2561429%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1105539%22%20target%3D%22_blank%22%3E%40SanatKMahapatra%3C%2FA%3E%26nbsp%3Bwow%20that%20a%20long%20time.%20depending%20on%20what%20information%20you%20want%20to%20return%20in%20the%20excel%20you%20could%20limit%20the%26nbsp%3B%24Info%20%3D%20%22%22%20%7C%20Select%20to%20reduce%20the%20content%20that%20is%20returned%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20to%20limit%20my%20next%20run%20by%20office%2Flocation%20but%20I%20haven't%20had%20the%20time%20to%20rework%20the%20PS%20yet%20to%20do%20that.%20But%20looking%20quickly%20you%20could%20add%20a%26nbsp%3B%7C%20where%20%7B%24_.CountryOrRegionDisplayName%20-eq%20%22xxxx%22%7D%20to%20the%20end%20of%20the%26nbsp%3B%24TeamsUsers%20%3D%20Get-CsOnlineUser%20%7C%20Select-Object%20section.%20That%20might%20work%20or%20use%20the%26nbsp%3BCountryAbbreviation%20property%20instead.%26nbsp%3B%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-2563912%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-2563912%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3EYes%2C%20you%20can%20update%20the%20top%20of%20the%20script%20to%20use%20a%20filter%20and%20select%20the%20attributes%20you%20want%20to%20filter%20on.%20%26nbsp%3BI%20would%20suggest%20you%20query%20some%20of%20your%20users%20and%20verify%20that%20the%20Teams%20PS%20Module%20sees%20those%20attributes%20before%20trying%20it.%20%26nbsp%3BFor%20example%3A%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BGet-CsOnlineUser%20%3CSPAN%3E-Filter%3C%2FSPAN%3E%3CSPAN%3E%20%7B%3C%2FSPAN%3ECountryAbbreviation%20%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-eq%3C%2FSPAN%3E%20%3CSPAN%3E%22US%22%3C%2FSPAN%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EOR%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BGet-CsOnlineUser%20-Filter%20%7BCity%26nbsp%3B-eq%20%22Phoenix%22%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EOR%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FSPAN%3EGet-CsOnlineUser%20%3CSPAN%3E-Filter%3C%2FSPAN%3E%3CSPAN%3E%20%7B(%3C%2FSPAN%3ECity%20%3CSPAN%3E-eq%3C%2FSPAN%3E%20%3CSPAN%3E%22Dallas%22%3C%2FSPAN%3E%3CSPAN%3E)%20%3C%2FSPAN%3E%3CSPAN%3E-or%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3ECity%20%3CSPAN%3E-eq%3C%2FSPAN%3E%20%3CSPAN%3E%22Phoenix%22%3C%2FSPAN%3E%3CSPAN%3E)%7D%3C%2FSPAN%3E%3CSPAN%20class%3D%22Apple-converted-space%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2564555%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-2564555%22%20slang%3D%22en-US%22%3EThank%20you%20so%20much%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1101368%22%20target%3D%22_blank%22%3E%40Dlewis-79%3C%2FA%3E%20%26amp%3B%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F984226%22%20target%3D%22_blank%22%3E%40JohnLockett%3C%2FA%3E%20for%20the%20inputs%2C%20I%20will%20reduce%20the%20amount%20of%20information%20needed%20for%20the%20first%20complete%20run%20even%20though%20I%20need%20all%20the%20attributes%20in%20the%20Info%20section%20of%20the%20script.%20Will%20apply%20the%20Filters%20to%20the%20Get-CSOnlineUser%20command.%3CBR%20%2F%3ECheers!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2787439%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-2787439%22%20slang%3D%22en-US%22%3EHi%20John%2C%3CBR%20%2F%3EGet-CSOnlineUser%20only%20returns%20a%20value%20for%20Teams%20policies%20when%20they%20have%20been%20assigned%20directly.%20When%20policies%20are%20inherited%20from%20a%20group%2C%20they%20don't%20show%20up.%3CBR%20%2F%3EGet-CsUserPolicyAssignment%20will%20only%20return%20information%20about%20policies%20assigned%20directly%20or%20inherited.%20It%20won't%20return%20anything%20if%20you%20have%20the%20global%20default%20policy%20which%20make%20it%20hard%20to%20use%20to%20report%20a%20decent%20report.%3CBR%20%2F%3EDid%20anyone%20find%20a%20work%20around%3F%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%2C%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2856139%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-2856139%22%20slang%3D%22en-US%22%3EThe%20filter%20only%20works%20is%20the%20polices%20have%20been%20directly%20assigned.%20If%20the%20user%20inherits%20a%20policy%20from%20being%20in%20a%20group%20then%20they%20do%20not%20show%20up%20in%20the%20results%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!

12 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.

 

@JohnLockett.... great piece of code! :smile:

@Timon-O
Please let me know how do you export the results to excel or CSV after applying the Filter on Teams Admin Center.
Regards
Sanat
Hi Sanat,

You don't there isn't an option in Teams Admin Center... thats why the about PowerShell is so useful.

Note - some of the properties in the above PS are not exported so you may have to add on TeamsAppPermissionPolicy.

Regards,

Damian
@JohnLockett @Dlewis-79 .. Thank you for the details and confirmation, it's really helpful.
I have only 1 query, It took 2.5+ days and the query was still running which collected over 38000+ User objects, however, I had to cancel as it entered today production hours.
Is there any way to limit or place a condition like CountryCode or ExtensionAttribute or CustomAttribute to pull a more small and specific report.

@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. 

 

 

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")} 

Thank you so much @Dlewis-79 & @JohnLockett for the inputs, I will reduce the amount of information needed for the first complete run even though I need all the attributes in the Info section of the script. Will apply the Filters to the Get-CSOnlineUser command.
Cheers!
Hi John,
Get-CSOnlineUser only returns a value for Teams policies when they have been assigned directly. When policies are inherited from a group, they don't show up.
Get-CsUserPolicyAssignment will only return information about policies assigned directly or inherited. It won't return anything if you have the global default policy which make it hard to use to report a decent report.
Did anyone find a work around?

Thanks,
The filter only works is the polices have been directly assigned. If the user inherits a policy from being in a group then they do not show up in the results