How to Downgrade Forest and Domain Functional Levels

Downgrade the Forest Functional Level Step 1. Open PowerShell with elevated privileges. Step 2. Execute the following command, replace the identity with your domain name and the forestmode with the level you want to downgrade to. Set-ADForestMode –Identity “CANITPRO.com” –ForestMode Windows2008Forest In the above example, I have downgraded the forest functional level to Windows Server 2008. ... Read more

Error when Executing a PowerShell Script for the First Time

When you are executing a PowerShell script for the first time you may encounter the following error: .... cannot be loaded because running scripts is disabled on this system. Why did this happen: PowerShell Execution Policies PowerShell has four execution policies for executing the script. Those four policies are described below: Restricted This is a default policy. ... Read more

How to Fix WinRm Firewall Exception Rule When Enabling PS Remoting

When you are enabling PowerShell remoting using the command Enable-PSRemoting, you may get the following error because your system is connected to the network trough a Wi-Fi connection. PS C:\WINDOWS\system32> winrm quickconfig The following changes must be made: Start the WinRM service. Set the WinRM service type to delayed auto start. Make these changes [y/n]? y ... Read more

How to Configure an IP Address Using PowerShell on Windows

If you are coming from Linux to Windows and you are used to working on the shell, then the following PowerShell commands might be the right ones for you. Get an IP Address Configuration You can use the following command to check the IP address configuration of your computer. It works the same way as ipconfig ... Read more

How to Set Up an Active Directory on Windows Server 2016 Using PowerShell

In this tutorial, I will explain how to install an active directory on Windows Core Server 2016 using a few PowerShell commands. If you have already configured an AD Domain Service before, you may be aware that there are the following two high-level steps: Installing Active Domain itself. Promoting the server as domain controller. Install ... Read more

How to Check if a User or Group Exists in AD using PowerShell

If you want to check the existence of any user or group in Windows Active Directory, use the following PowerShell script. PowerShell: Check if AD User or Group Exists Step 1. Open PowerShell with elevated privileges. Step 2. Execute the following script: $userobj = Get-ADUser -LDAPFilter "(SAMAccountName=$username)" $vlanobj = Get-ADGroup -LDAPFilter "(SAMAccountName=$vlangroupname)" if ($userobj -eq ... Read more

How to Prompt a User for Input using PowerShell

You can use the read-host command-let to get an input from a user during program execution. PowerShell Input Example Here is a related example, the program gets two numbers in string format and converts them into integers and then sums up those numbers and finally displays the result. The -prompt parameter is used to display a ... Read more

How to Read a Text File Using PowerShell

You can read a text file and display its content using get-content cmdlet in PowerShell. Read textfile example Execute the following command on PowerShell with elevated privileges. Get-Content c:\scripts\test.txt This command will display the contents of the file test.txt which is located in c:\scripts\

How to Generate Random Numbers Using PowerShell

When you have to generate random passwords for users, you can execute the get-random command let on PowerShell to create it. Generate Random Number get-random -maximum 2000 -minimum 100 This command, when executed on PowerShell, creates a number between 1999 (not 2000 and always set one number higher in maximum) and 100.