One Line: Apply Policies To Lync Users Not in a Group

A while ago I wrote about one line of PowerShell to bulk enable users based on group membership.  The question has recently come up, what if they’re not in a group?  That’s a little bit trickier, but not too rough.

Why might you want to do this?  Perhaps we want to set a policy for everyone but exclude certain executives or the sales department.  Another example, let’s say we have two mobility policies, MobilityEnabled and MobilityDisabled.  We could run a scheduled task that grants MobilityEnabled for all Lync users in a group, but for those who have been removed for the group, we want to turn it off by granting MobilityDisabled (if you don’t want any specific policy, use $null).

As I’ve suggested in my other article, there are scripts that can do this as well.  Those scripts will give you more flexibility to add additional commands, but I like personally also like to keep one-liners that I can quickly cut and paste during administrative work.

It’s easy to illustrate this with an example using the Grant-CsMobilityPolicy scenario above:

Get-CsUser | ForEach {$myuser=$_;if (-not (Get-ADGroupMember “Your Group” | Where { $_.samaccountname -eq $myuser.samaccountname } )) { Grant-CsMobilityPolicy $myuser.identity -policyname “MobilityDisabled“}}

Swap the Grant-CsMobilityPolicy command for anything you’d like.

Of course, if you like this command as the one-liner to add based on a group better than the method mentioned in my previous article, just remove the -not, there are always many ways to accomplish the same thing with PowerShell.

 

2 thoughts on “One Line: Apply Policies To Lync Users Not in a Group

  1. Pingback: NeWay Technologies – Weekly Newsletter #105 – July 24, 2014 | NeWay

  2. Pingback: NeWay Technologies – Weekly Newsletter #105 – July 25, 2014 | NeWay

Comments are closed.