Windows Server 2012 and other operating systems (Windows 8, 8.1) have the ability to use Windows PowerShell commands that are built on .NET framework. Windows PowerShell is a powerful command line that allows administrators to perform any adding, changing of any option you see on the Graphical User Interface (GUI), and perform other manipulations that can’t be done from the GUI, thus expending the Administrators power and capabilities.
Most people will find PowerShell difficult to use and time consuming when making changes. While they can perform the same thing on the GUI, PowerShell has the ability to perform other manipulations that grant you more control, reliability, and scalability all while saving you a lot of time. For example, you can execute the same command on multiple computers and perform many tasks, which you normally do separately, in just one single line.
Windows Server 2012 comes with two versions of PowerShell:
- PowerShell (regular version): Looks like a DOS command prompt and executes all the commands in DOS plus cmdlets that only PoweShell can perform.
- PowerShell ISE: Enhanced version of PowerShell. Can write, test and debug in the same window, as well as support telesense which helps you to choose commands.
In this article, I will touch on a few regular and some special commands to show you the capabilities of PowerShell.
Before starting, if you create a user, group, or OU name with spaces, you MUST enter it between double quotes i.e.: “My City OU”
-Creating an Organizational Unit (OU)
-Creating a user inside an Organizational Unit (OU)
-Setting a password for the user
-Setting the password for the user in question in Windows PowerShell
Once you hit enter a popup window will ask you for the password for the user in question.
The popup window will prompt you for the OLD password then will ask you to enter a new one and confirm it.
– Adding a group
When creating a group, you need to specify the scope (Domain local, global, or Universal) and the category (Security, or Distribution)
– Adding a user to a group
– Removing a user from the group
When removing a user from the group you are only making that user lose his membership to that specific group.
– Removing an Organizational Unit (OU)
Deleting an object OU will delete all the objects inside it; therefore, you must be very careful.
Normally, and by default, OUs are protected from accidental deletion, therefore before you delete you must either:
1- Go to properties for the OU and under the tab “Object” (Need to be on advanced feature) uncheck <Protect object from accidental deletion> click Apply then OK.
After unchecking the option, you can type in the command and hit enter. A confirmation box will then pop up to confirm your action of deleting the OU.
2- Another option is to type in the command from the PowerShell as follows:
Extended commands that can only be done using PowerShell
1- Remote to another server:
Once you hit enter you will be prompted to enter your password:
If you get an error (Enter-PSSession: Connecting to remote server server_ name failed with the following error message: WinRm cannot process the request) accessing the computer name, you need to enable the WinRm from the server you want to remote into using its PowerShell:
As an answer you will get “WinRM firewall exception enabled”.
Enabling or disabling your firewall would not make any difference.
If you want to activate the WinRM on all computers automatically, you will need to run the following command from the AD server:
Get the list of computers that you want to have WinRm active.
Set the list of servers to have WinRm automatically enabled.
2- Get XX number of event logs from different computer(s)
With the command below you can view XX number of security event logs for one or more computers (separated by commas) in your environment. In the command below, we are only retrieving 10 security event logs.
Or simply if you want to get to choose a computer name each time you run this command, just run the following:
3- Get last 10 security event logs from all computers:
The following command will get the last 10 security event logs from all computers in your environment:
4- Shutting down one, two or all computers in your organization (be careful):
Leave a Comment