[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4623
  • Last Modified:

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?
0
marrj
Asked:
marrj
  • 4
  • 3
1 Solution
 
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now