Todays one liner

This one liner is in the same area as my two other posts. It will disable every user in Skype for Business, thats allready disabled in Active Directory.

First you use the Get-AdUser commandlet and set a filter to find every disabled user account in Active Directory.
Then you have to pipeline it to Disable-CSUser, but this wont work.
You will get this error:

ForEach-Object : The script block cannot be invoked because it contains more than one clause. The Invoke() method can only be used on scrip
t blocks that contain a single clause.
At line:1 char:45
+ Get-AdUser -Filter { Enabled -eq $False } | ForEach-Object {
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [ForEach-Object], PSInvalidOperationException
+ FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.ForEachObjectCommand

Im verry new to PowerShell, but as i understand it does not support pipelining a list of users directly into the commandlet.
If you create a Foreach statement it will work. You will end up with a one liner looking like this:

one liner

In Skype for Business, disable is the same as to delete the user. If you want to temporary disable it, so you keep all settings for the user, you can use Set-CsUser -Enabled $False instead.


Both lines will create an error for each disabled user in AD that does not exsist in Skype for Business. I will update this post when my PowerShell skills are good enough to make the output look nicer 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s