Powershell
Last updated
Last updated
PowerShell is a versatile tool that works across different platforms. It combines:
A command-line interface (CLI)
A programming language for scripting
Tools for managing system settings
Its main purpose is to help automate repetitive tasks, like handling large sets of data, and to simplify the creation and execution of scripts that manage system operations. This makes it an essential utility for automating system maintenance and managing configurations efficiently.
PowerShell cmdlets consist of a verb and a noun
Many native windows commands will work in the PowerShell window. For example ping, Ipconfig
Open Powershell and run it as an administrator to remove any restrictions on the commands you can execute.
Let's try a few basic commands first. There are many aliases to make transitioning to the PowerShell environment easier.
cls –> Clear-Host
cd –> Set-Location dir
ls –> Get-Children
PowerShell's help system is robust, thoughtfully designed, and serves as an excellent reference tool. It also receives frequent updates to correct errors and enhance usability.
Use
cmdlet in PowerShell while connected to the Internet to update the PowerShell help files.
After updating the Help function in PowerShell, use the 'Get-Help' cmdlet to retrieve information about a few cmdlets containing a specific keyword.
For example:
Get-Help *Process* in PowerShell retrieves help information about any cmdlets, functions, or modules containing "Process" in their names.
Get-Help *Service* in PowerShell retrieves help information about any cmdlets, functions, or modules containing "Service" in their names.
The asterisks (*) act as wildcards, representing zero or more characters
The Pipeline - The piping character sends the output from one cmdlet to the input for another cmdlet. It can all be typed on 1 line or it can be broken up onto multiple lines as shown in the two images.
Displaying information in GUI - Grid-view windows makes this possible
For example
Cmdlets that kill - Most commonly used cmdlets to terminate an application or process through PowerShell are:
Stop-Process
Kill-Process
When uncertain about the outcome of a command, you can use the -WhatIf parameter to simulate its execution without making any changes. Alternatively, the -Confirm parameter prompts you for confirmation before proceeding with an action.
For example:
Finding and Adding Modules - Get-Module will list installed modules, using the –ListAvailable parameter shows the available PowerShell modules and Import-Module will add the module that you need.
Selecting Obejcts - The output of a cmdlet normally has a default set of properties that will be displayed, this can be modified to add or remove displayed properties by using the Select-Object cmdlet.
Sorting Objects - Pipping the output of a cmdlet to the Sort-Object cmdlet allows sorting of the output in a descending or an ascending manner.
Let's install DHCP, DNS and Active Directory services through PowerShell
I already have ADDS install on my Domain Controller so the Exit Code is NoChangeNeeded and nothing was installed
Let's explore a few more Powershell commands on the Windows Server Domain Controller.