powershell scrips used for batch sysadmin tasks in microsoft active directory
remove-ad-computers.ps1
Permanantly removes and deletes computers from Active Directory.disable-ad-computers.ps1
Disables computers within AD and optionally moves them to the "disabled computers" OU. see the note below for additional steps required to allow this functionality. It is disabled by default.disable-ad-users.ps1
Disables user accounts within AD and optionally moves them to the "disabled users" OU. see the note below for additional steps required to allow this functionality. It is disabled by default.remove-programs.ps1
Uninstalls programs on a specific machine. Coming soon: Uninstall a list of progrms on multiple machines at once!delete-old-files.ps1
Removes files older thanx
number of days from a specific folder. This also recurses through the folder and deletes files in child folders, as well as empty folders.
- Create a text file with the users or computers that need to be managed. Each usename or hostname should be on its own line.
- If you are removing computers from AD, name the file
deletecomputers.txt
- If you are disabling computers from AD, name the file
removecomputers.txt
- If you are disabling users within AD, name the file
removeusers.txt
- If you are removing computers from AD, name the file
- Log in to the remote Domain Controller as a domain administrator.
- Copy the appropriate PowerShell script and text file for the action being completed onto the remote DC’s desktop.
- Run a new PowerShell window as administrator
- In the new powershell window:
- If you are removing computers from AD: type
C:\users\[admin username]\Desktop\remove-ad-computers.ps1
- If you are disabling computers from AD: type
C:\users\[admin username]\Desktop\disable-ad-computers.ps1
- If you are disabling users within AD: type
C:\users\[admin username]\Desktop\disable-ad-users.ps1
- If you are removing computers from AD: type
- Run the command and prosper!
NOTE: In order to activate the movement of users between Organizational Units in AD, you must first uncomment the command that moves them, and second paste the appropriate distinguishedName
of the Disabled Users OU. This applies to scrips that disable AD Users or Commputers, but do not remove them.
- Create a text file with a lsit of programs that need to be removed from a machine. Name the file
removeprog.txt
. - Log into an administrator account on the computer that you are managing.
- Copy the
remove-programs.ps1
script and theremoveprog.txt
file onto the administrator's desktop. - Run a new PowerShell window as an administrator.
- In the window, type
C:\users\[admin username]\Desktop\remove-programs.ps1
- Run the command and go out for lunch. This process might take a while.
- Locate the directory with old files that you want to delete.
- Copy the
delete-old-files.ps1
script onto the desktop of your compter. - Open a new PowerShell window.
- In the new PowerShell type
cd C:\Users\[username]\Desktop
, then press enter. - Then, type
.\delete-old-files.ps1 <directory with files to be deleted> <minimum age of files to be deleted (in days)>
and press enter. - You should see output on the screen that the script is deleting items.
- You may be promped to delete empty folders. Feel free to say "yes" this prompt.