Retrieve All Global Lync Server Policies

How can I retrieve all the global policies?


This turned out to be a very frustrating question for us, simply because we almost had a really good answer to it. Unfortunately, though, we have a few quirks in our cmdlet naming conventions and, because of that, we don't have a really good answer to it after all. In fact, the best answer we have is pretty lame: just write a script that, by brute force, retrieves each global policy. You know, like this:


Get-CsArchivingPolicy –Identity global

Get-CsClientPolicy –Identity global

Get-CsClientVersionPolicy –Identity global

Get-CsConferencingPolicy –Identity global


Etc., etc.


The reason this is frustrating (as we hinted at) is because we have a naming convention for our cmdlets that, if we'd stuck to it, would have made this a pretty simple task. Most of our cmdlets for retrieving policies end in the word policy: Get-CsArchivingPolicy; Get-CsClientPolicy; Get-CsVoicePolicy. If all the cmdlets for retrieving policies ended with the word policy then we could just write a simple little script that said, hey, go grab all the Get-Cs cmdlets that end with the word policy and use them to retrieve the corresponding global policy.


Unfortunately, though, we can't do that. Why not? Well, for one reason, there's the cmdlet Get-CsNetworkInterSitePolicy. That cmdlet retrieves a policy all right, but not the kind of policy that is applied to user accounts. (And that's the only kind of policy we're interested in for now.) For another, there's Get-CsDialPlan, which retrieves dial plan information. The dial plan is actually a policy (in the sense that it's something we can assign to users), but it's called a dial plan rather than a policy. As a result, a command that retrieved all the Get-Cs cmdlets that have a name that ends with the word policy would return network inter-site policies (which we don't want) and wouldn't return dial plans (which we do want).


Frustrating, to say the least.


That's why we suggested just writing a script that calls each policy retrieval cmdlet one-by-one. It's not very cool and it's not very exciting, but it'll work.


Alternatively, you could try this little script, which is a sort of hacked-together conglomeration that retrieves all the Get-Cs policy cmdlets unless the word Network is found somewhere in the cmdlet name. Oh, and, for good measure, it also grabs the Get-CsDialPlan cmdlet as well:


$allNouns = (Get-Command –Module Lync | Where-Object {($_.Name –like "Get-Cs*Policy" –and $_.Name –notlike "*Network*") –or $_.Name –like "Get-Cs*DialPlan"}


foreach ($noun in $allNouns)


        $name = "Get-" + $Noun.Noun


        Invoke-Expression "$name –Identity global"



 Not particularly elegant but it works. And, for now at least, it's about the best we can do.


Note. Does that mean that, somewhere in our secret Lync Server laboratory, we're trying to come up with a better way to do something like retrieve a list of all the policy cmdlets or all the voice-related cmdlets? Let's put it this way: stay tuned.


But don't hold your breath.

Skip to main content