List all SfBS & SfBO policies by type

Here’s a “one-liner” I came up with this week that dumps ALL of the SfB policies in your system ordered by type:

PS C:\> Get-Command -Module SkypeForBusiness Get-Cs*Policy | where-object {$_.Name -ne "Get-CsEffectivePolicy"} | ForEach { invoke-expression $_.name  } | ft @{Label="Policy type"; Expression={($_.getType()).ToString().Split('.')[-1]}}, identity -auto

This is what it looks like here in the GIS lab:


Despite its apparent complexity it breaks down neatly into 4 steps, each separated by the pipe character (“|”).

Get-Command -Module SkypeForBusiness Get-Cs*Policy |
where-object {$_.Name -ne "Get-CsEffectivePolicy"} |
ForEach { invoke-expression $_.name  } |
ft @{Label="Policy type"; Expression={($_.getType()).ToString().Split('.')[-1]}}, identity -auto
  1. Capture all of the “Get-Cs<something>Policy” commandlets in the SfB module.
  2. Get-CsEffectivePolicy isn’t a policy type per-se, so pull it out of the list.
  3. Run each of the commandlets in the list, which will output EVERYTHING.
  4. Format the output into an object with two columns: the first (“PolicyType”) is the GetType property of each policy, formatted to strip all the bumpf and only retain the raw type; and finally the identity of the object – the policy’s name. And -auto makes sure the names aren’t truncated.

 

SfBO

Here’s the version for Skype for Business Online:

PS C:\> Get-Command -Module tmp_* Get-Cs*Policy | where-object {$_.Name -ne "Get-CsEffectivePolicy"} | ForEach { invoke-expression $_.name  } | ft @{Label="Policy type"; Expression={($_.key.Split('},'))[1]}}, identity -auto

It’s essentially the same as the on-premises version, just reading a different module, and fishing out the object type from a different location.

Please let me know if this doesn’t work for you, because I’m taking a little liberty here: the module name isn’t constant. The only part that’s constant is “tmp_” at the start. Should another installed module follow this – um, “erratic’s” too harsh – variable naming structure, the cmdlet will probably fail.

Microsoft Teams

This one’s not applicable to Microsoft Teams at this stage, as any policies you’re applying to the user are via the SfBO module.

Variations?

Want to maybe dump *everything* as part of an as-built document? Try this, which places a marker in the document with the name of the policy type, before then dumping each of the policies themselves:

Get-Command -Module SkypeForBusiness Get-Cs*Policy | where-object {$_.Name -ne "Get-CsEffectivePolicy"} | ForEach { write-output "## $($_.name)" ;invoke-expression $_.name  } | out-file -FilePath c:\SfBPolicies.txt

In this example I’ve prefixed the policy type with “## “, so it’ll be bolded if you open the document in a markdown reader, but equally it will be just as easy to use that as a search term in Word to remove the characters and apply a style.

 

Revision History

21st May 2020: this is the initial publication.

 

– G.

Leave a Reply

Your email address will not be published.

... and please just confirm for me that you're not a bot first: Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.