Updated March 23, 2023
Introduction to Windows Powershell commands
The following article provides an outline for Windows Powershell Commands. Windows PowerShell is a scripting language that is built on .net platform designed to automate the tasks related to windows application and administration. The term PowerShell is a combination of the language and the interface in which the commands/scripts will be run. The first version of PowerShell was introduced in the year 2006. There are two types of interfaces where can PowerShell commands can be run; windows PowerShell is like a command prompt where PowerShell cmdlets can be run, and Windows PowerShell ISE is where PowerShell scripts (a compilation of PowerShell cmdlets) can be run and debugged. It is an object-oriented language thereby allowing it to integrate with .net interfaces. It is now open-source and can be installed on other OS’s as well.
To start a PowerShell session, type “PowerShell” in the command prompt PowerShell cmdlets and variables. The commands in PowerShell are referred to as “cmdlets”. The available list can be got by running the below cmdlet.
Code:
Get-Command
The above returns almost 1500 PowerShell cmdlets that are available within PowerShell.
Top 11 Essential and Powerful cmdlets
Here are the top 11 essential Windows PowerShell Commands which are given below:
1. Get-Help
For any human being to remember the syntax or the cmdlets any programming language is difficult and a tedious task. To overcome this challenge PowerShell has numerous help articles. To get help about any PowerShell cmdlet the Get-Help cmdlet can be used. It provides the syntax and the way to use it to a cmdlet.
Syntax:
Get-Help “Cmdletname”
Example:
Get-Help Get-Process This will display the syntax and the aliases of Get-Process Cmdlet
2. Set-ExecutionPolicy
The set execution policy is used to determine the policies for running a PowerShell cmdlet or script. In order words, it is used to prevent certain actions from all the users. It is used to give some special permission.
Syntax:
Set-ExecutionPolicy
[-ExecutionPolicy] <ExecutionPolicy>
[[-Scope] <ExecutionPolicyScope>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Example:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
In the above example, a remote signed policy is applied to the current user.
3. Get-ExecutionPolicy
Before running a command or script on any environment, it is advisable to know the current execution policy that is in place. The Get-ExecutionPolicy is used for that purpose.
Syntax:
Get-ExecutionPolicy
[[-Scope] <ExecutionPolicyScope>]
[-List]
[<CommonParameters>]
Example:
Get-ExecutionPolicy -List
Output:
The above displays the execution policy for the current PowerShell session.
4. Get-Service
The above cmdlet returns all the available services.
Syntax:
Get-Service
[[-Name] <String[]>]
[-DependentServices]
[-RequiredServices]
[-Include <String[]>]
[-Exclude <String[]>]
[<CommonParameters>]
Example 1:
Get-Servicek
The above will return the list of all available services.
Example 2:
Get-Service -Displayname "*network*"
The above returns the services whose name contains a network.
5. Export-CSV
The above command is to export the output of a cmdlet or script to a csv file.
Syntax:
Export-Csv
[[-Path] <string>]
[[-Delimiter] <char>]
-InputObject <psobject>
[-LiteralPath <string>]
[-Force]
[-NoClobber]
[-Encoding <Encoding>]
[-Append]
[-IncludeTypeInformation]
[-NoTypeInformation]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Example:
Get-Command | Export-CSV c:\commands.csv
The above will output the list of available commands to the CSV file.
6. Get-EventLog
The above command returns the events in the event viewer of the system.
Syntax:
Get-EventLog
[-LogName] <String>
[-ComputerName <String[]>]
[-Newest <Int32>]
[-After <DateTime>]
[-Before <DateTime>]
[-UserName <String[]>]
[[-InstanceId] <Int64[]>]
[-Index <Int32[]>]
[-EntryType <String[]>]
[-Source <String[]>]
[-Message <String>]
[-AsBaseObject]
[<CommonParameters>]
Example:
Get-EventLog -Log "Application" - Newest 10
The above returns the top 10 application logs.
7. Get-Process
To know the set of processes that are currently running on the system.
Syntax:
Get-Process
[[-Name] <String[]>]
[-Module]
[-FileVersionInfo]
[<CommonParameters>]
Example:
Get-Process | Where-Object {$_.WorkingSet -gt 70000000}
Running the Get-Process displays the below result.
Output:
The above cmdlet displays processes who are occupying more than 70 MB.
8. Stop-Process
As the name implies, the above cmdlet is to kill a process.
Syntax:
Stop-Process
[-Id] <Int32[]>
[-PassThru]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Example 1:
Stop-Process -Name "calc"
The above cmdlet stops the calculator process.
Example 2:
Stop-Process -ID 2668
The above kill the process with the corresponding id.
9. Where-Object
It is used for filtering purposes.
Syntax:
Where-Object
[-InputObject <PSObject>]
[-Property] <String>
[[-Value] <Object>]
[-EQ]
[<CommonParameters>]
Example:
Get-Service | Where-Object {$_.Status -eq 'Running'}
The above command returns the services which are currently running.
10. Checkpoint-Computer
Whenever carrying out a risky assignment, this cmdlet is used. It creates a restoration point on the system.
Syntax:
Checkpoint-Computer
[-Description] <String>
[[-RestorePointType] <String>]
[<CommonParameters>]
Example:
checkpoint-computer -description "restorpoint"
11. Get-Counter
This cmdlet is used to identify the various parameters that affect the performance of the system.
Syntax:
Get-Counter
[[-Counter] <String[]>]
[-SampleInterval <Int32>]
[-MaxSamples <Int64>]
[-Continuous]
[-ComputerName <String[]>]
[<CommonParameters>]
Example:
Get-Counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 5 -MaxSamples 2
The above command gets the processor time for two samples in five seconds interval.
Output:
Conclusion – Windows Powershell Commands
Thus, the article covered a few of the top Powershell cmdlets. There are around more than 1500 cmdlets available in Powershell and the best way to know about them is to use the get-help command for them and explore them.
Recommended Articles
This is a guide to Windows Powershell Commands. Here we discuss the top 11 windows Powershell commands along with the syntax and examples. You can also go through our other suggested articles to learn more –