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.

http://blogs.technet.com/b/meacoex/archive/2011/04/24/powershell-script-get-group-members-and-check-for-users-that-are-not-enabled-for-lync-and-enable-these-users-using-e-mail-address.aspx 
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?
LVL 1
marrjAsked:
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.

SubsunCommented:
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

0
Jakob DigranesSenior ConsultantCommented:
I really cannot take credit for this; but Lasse Nordvik Wedø ---- Lync Master:
http://tech.rundtomrundt.com/p/lync-ps-commands.html
0
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?
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

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.
0
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.
0
SubsunCommented:
Try..
Get-ADGroupMember LyncGroup | %{Get-CsAdUser $_.SamAccountName | ? {$_.enabled -ne $true} | Enable-CsUser -RegistrarPool lyncse.coex.com -SipAddressType EmailAddress}

Open in new window

0

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?
0
SubsunCommented:
% 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
http://ss64.com/ps/foreach-object.html
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.