PowerShell OSD scripts to Add/Remove Computer from AD group and set AD Description

I checked the statistics for my blog and comments as well, the “old” vbscripts I wrote to Add a Computer to an AD group and Set AD Computer Description as still being downloaded, used and commented on. I mostly use webservices to manage tasks like this now, but they are still being used out there so it is time to update them to Powershell!

Here are three of the scripts in Powershell instead, AddtoADGroup, RemoveFromADGroup And SetADdescription. They can be downloaded here:

All scripts have to run in full OS and not in WinPE.

AddToADGroup

The script adds the computer it is being executed on to one or more AD Groups. “:” is the separator and if there is a space in the group name use “” as well. The account used to run the step must have permissions in AD to execute the command.
Example command line:
Powershell.exe -NoProfile -ExecutionPolicy Bypass –File AddToGroups.Ps1 “group1”:”group2”

RemoveFromADGroup

The script removes the computer it is being executed from one or more AD groups. “:” is the separator and if there is a space in the group name use “” as well. The account used to run the step must have permissions in AD to execute the command.
Example command line:
Powershell.exe -NoProfile -ExecutionPolicy Bypass –File RemoveADGroups.Ps1 “group 1”

SetADDescription

Sets a Description in AD on the computer object in AD it uses the name of the computer it is being executed on. Use “” around the description if the description contains spaces.

Example Command Line:
Powershell.exe -NoProfile -ExecutionPolicy Bypass –File SetComputerDesc.Ps1 “Test Computer”

 

15 Comments

Add a Comment

Your email address will not be published. Required fields are marked *