These scripts are fairly simple and were used to test scripting with Powershell inside my Active Directory Homelab. You can read more about it on my website.
{ On top of the first 2 scripts, of which you can find screenshots and a short guide, additional scripts might be added over time, all tested and used in Virtual environments }
- Using and Managing Windows Server and Windows 10/11 within Virtual Machines. (VMware / VirtualBox)
- Configuration of Active Directory services, DHCP, DNS, GPOs and so on.
- Basic scripting and automation with Powershell for common use cases.
A brief description of the PowerShell utility scripts present in this repository.
- The first script,
Generate_Users.ps1, will automatically add any number of users to the Active Directory database, by taking the list of names and surnames from the filelistnames.txt, and creating a folder called_USERS, keep in mind that you can change the name of the folder. You will specify name and surname in the txt file of each user that you would like to add, follow the format of the examples already present inlistnames.txt, that is "first name" + space + "last name".
The first line of thelistnames.txtfile is a placeholder for your name and surname, if you want to add yourself as the first user who gets added to AD.
- The second script,
Clear-all-printjobs.ps1, will clear the printing queue and cancel any print jobs that might be there. It could be useful to troubleshoot issues with your printer (if the issue is software related, and not hardware related), if for example the print spooler is stuck then clearing the print job queue could fix the issue.
This script will also get and display the name of the printers (if any) and let you know if any print job has been cancelled.
- The third script, called
info-system.ps1, shows the system information (such as BIOS, CPU, RAM, OS Version etc.) of your local computer. It uses the Windows Management Interface (WMI) cmdlet: WMI is a popular management interface that can access data of a given computer. However, WMI is being deprecated, and PowerShell today relies heavily on PSRemoting and the security features it includes, which is why I recommend using the Get-CIMInstance cmdlet instead for more complex/security-related scripts.
- The fourth script, called
windows-defender.ps1, gives the user 3 options to pick from, all related to Windows Defender: Option 1) checks the Windows Defender status and shows the scheduled scan day, Option 2) Disables real-time protection, Option 3) Enables real-time protection. Useful in test environments where you want to quickly disable/enable Windows Defender or see its current status.
It's also very useful to learn CLI (command-line interface) commands to quickly perform actions that are done often (possibly daily), which saves a lot of time. Here are some examples of a few useful commands:
- Resets the password of a given user:
Set-ADAccountPassword <User> -Reset -NewPassword (Read-Host -AsSecureString -Prompt 'New Password') - Checks if there are any accounts with an expired password:
Search-ADAccount -PasswordExpired - Unlocks a given user account:
Unlock-ADaccount -identity "User" - Extracts a list of users which are part of a given AD Group:
Get-ADGroup <Groupname> | Get-ADGroupMember
- Windows 10/11, Windows Server 2022
Run Windows PowerShell ISE with admin rights and enter the following line to be able to run the Generate_Users script (you can change it back after):
Use the cd command to go where the txt file is stored:
Alternatively, you can put the path of where the txt file is stored directly into the code of the script.
The Generate_Users script in function:
Keep in mind that what's being displayed is the "username", which is a combination of the first letter of the first name and the full last name (e.g. Adam Smith will have the username of "asmith"), if you check the profile associated with those usernames in Active Directory you will also find the full first name and last name of each user.
For the second script, simply execute the PowerShell file and it will clear all the print jobs:

