Powershell - Enable Lync 2013 Users Based on Group Membership

I am trying to write a Powershell script that enables Lync users based on their AD group membership.

I found this script, but it doesn't work.  I get this error.

Enable-CsUser : Cannot convert 'System.Object[]' to the type 'Microsoft.Rtc.Management.AD.UserIdParameter' required by parameter 'Identity'. Specified method is not supported.
At C:\Scripts\Lync_Test_Enable.ps1:9 char:25
+ Enable-CsUser -identity $aduser.identity -RegistrarPool lyncse.coex.com -SipAddr ...
+                         ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Enable-CsUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Rtc.Management.AD.Cmdlets.EnableOcsUserCmdlet

Any ideas on how to make this a functional script and satisfy the identity parameter?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subash SundharanIT Infrastructure Architect Commented:
You can try this simple version..replace lyncse.coex.com with your pool name and LyncGroup with your group name
Import-Module activedirectory
Import-Module lync
Get-ADGroupMember LyncGroup | Get-CsAdUser | ? {$_.enabled -ne $true} | Enable-CsUser -RegistrarPool lyncse.coex.com -SipAddressType EmailAddress

Open in new window

Jakob DigranesSenior advisorCommented:
I really cannot take credit for this; but Lasse Nordvik Wedø ---- Lync Master:
marrjAuthor Commented:
Thanks, but I'm having trouble getting either one of these methods to work.

Subsun, I get an error stating that the "Get-CsAdUser" cannot accept pipelined input or the parameters dont' match the cmdlet being piped.

jakob_di, I believe the "foreach" is missing a parameter or two.  It won't run in its current state.  

Any more ideas?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

marrjAuthor Commented:
jakob_di, I finally got your version to get past the foreach loop, but I run into problems when satisfying the Identity requirement of the CS command, as Get-ADGroupMember.Name does not return something that is usable by the Enable-CsUser command, just as I ran into with my own version.
marrjAuthor Commented:
THis is what pointed me to the use of the "Get-CsAdUser" cmdlet, but I get a similar error about mismatched properties when using it as well.
Subash SundharanIT Infrastructure Architect Commented:
Get-ADGroupMember LyncGroup | %{Get-CsAdUser $_.SamAccountName | ? {$_.enabled -ne $true} | Enable-CsUser -RegistrarPool lyncse.coex.com -SipAddressType EmailAddress}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marrjAuthor Commented:
Awesome!  That worked.  

What does the %{} do exactly?
Subash SundharanIT Infrastructure Architect Commented:
% is an alias for ForEach-Object which i used to loop through the results of command Get-ADGroupMember

Refer following article to know more details about ForEach-Object
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.