Lever­ag­ing the ap­pro­pri­ate Pow­er­Shell commands lets you employ modules with precision. These well-organized cmdlets can be further tailored through optional pa­ra­me­ters. We present the 40 most essential Pow­er­Shell commands so that you can work optimally in your system or network.

What is a Pow­er­Shell command?

Pow­er­Shell, which comes pre­in­stalled since Windows 7, allows you to enter Pow­er­Shell commands that are then executed by Windows. In addition to the command line’s cmd commands, there are numerous other commands or cmdlets that can only be un­der­stood by Pow­er­Shell itself. These cmdlets consist of a verb and a noun, which are separated by a hyphen. Ad­di­tion­al­ly, you can enhance these Pow­er­Shell commands with optional pa­ra­me­ters, separated by spaces. Pow­er­Shell’s utility extends beyond ad­min­is­tra­tors; it also proves in­valu­able in the realm of de­vel­op­ment. With a plethora of pre-installed Pow­er­Shell commands available, we acquaint you with the most pivotal ones.

The most important Pow­er­Shell commands

Pow­er­Shell commands allow you to carry out extensive admin tasks in just a few entries. Among the basic commands that you’ll likely use most fre­quent­ly are those that offer an initial overview of your network’s structure, list other Pow­er­Shell commands, assist in essential security con­fig­u­ra­tions, and enable valuable analyses. Here are some of the most crucial Pow­er­Shell commands you should be familiar with:

1. Get-Module -All

To gain an initial overview of all imported Pow­er­Shell modules, use the command Get-Module -All.

Get-Module -All
shell

2. Get-Command

There is an abundance of pre-defined Pow­er­Shell commands. To obtain an overview of the currently available Pow­er­Shell commands, simply use the Get-Command command. This command will neatly list all potential actions and offer concise ex­pla­na­tions for each re­spec­tive cmdlet. This holds true even if you have installed ad­di­tion­al modules.

Get-Command
shell

3. Get-Help

The Get-Command list described above provides an initial overview; for more detailed in­for­ma­tion about a command and its options, use the Get-Help cmdlet. This command accesses the help files on your PC and then provides all available in­for­ma­tion. To activate it, combine Get-Help with the command whose syntax you want to view.

Get-Help [[-Name] <String>] [-Path <String>] [-Category <String[]>] [-Component <String[]>] [-Functionality <String[]>] [-Role <String[]>] [-Examples] [<CommonParameters>]
shell

4. Get-Process

To rapidly check the list of currently active ap­pli­ca­tions, programs, and processes on your system, you can use the Get-Process command. If you specify a par­tic­u­lar ap­pli­ca­tion, you’ll receive ad­di­tion­al in­for­ma­tion about that specific ap­pli­ca­tion.

Get-Process
shell

5. Get-Service

The Get-Service command functions similarly to the Get-Process cmdlet. However, it dis­tin­guish­es itself by offering in­for­ma­tion about all active services. If you wish to obtain in­for­ma­tion about a par­tic­u­lar service or a specific category of services, you can easily specify your request.

Get-Service
shell

6. Stop-Process

You can also use various Pow­er­Shell commands to stop processes via the shell. One option is the Stop-Process command. You define the cor­re­spond­ing process by name, ID or with other at­trib­ut­es. Here’s an example:

Stop-Process -Name "processname"
shell
Stop-Process -Id 3582 -Confirm -PassThru
shell

A con­fir­ma­tion of the command is requested with -Confirm. The -PassThru command requests con­fir­ma­tion of the stopped process. This is not done au­to­mat­i­cal­ly.

7. ConvertTo-HTML

To swiftly identify problems or potential com­pli­ca­tions, having a clear display is in­cred­i­bly ben­e­fi­cial. You can achieve this by utilizing the ConvertTo-HTML command, which transfers the output of your Pow­er­Shell commands into an HTML file. This presents the in­for­ma­tion in a user-friendly column format. The command structure typically looks like this:

Get-Command | ConvertTo-Html > c:\temp\AllCommands.html
shell

8. ConvertTo-Xml

You can proceed in a similar way if you require an XML-based rep­re­sen­ta­tion of a specific object. You can do this with the ConvertTo-Xml command. In the following example, you convert the current date into XML format:

Get-Date | ConvertTo-Xml
shell

9. Where-Object

You can use the Where-Object command to filter the result of a cmdlet. When you execute a command, you may often receive numerous objects that contain more in­for­ma­tion than you require. By using Where-Object in con­junc­tion with a pipe, you can display only the specific in­for­ma­tion you are seeking. For instance, if you want to view services created or updated this year, you can do so as follows:

Get-Service | Where-Object { $_.LastWriteTime -gt "01.01.2023" }
shell

10. Get-History

To list all Pow­er­Shell commands that you’ve entered during a session, Get-History is the right cmdlet. To list all Pow­er­Shell commands:

Get-History
shell

With this spec­i­fi­ca­tion, you only call the last ten Pow­er­Shell commands:

Get-History -Count 10
shell

11. Clear-History

You can also delete the list of Pow­er­Shell commands used. To remove all entries, use the cmdlet Clear-History:

Clear-History
shell

To delete select Pow­er­Shell commands, simply add the cor­re­spond­ing pa­ra­me­ters. The following input removes all Pow­er­Shell commands that contain “Help” or end with “Syntax”.

Clear-History -Command *Help*, *Syntax
shell

12. Add-History

It’s also possible to add Pow­er­Shell commands to a session. This allows you to call them up again later on. The ap­pro­pri­ate cmdlet is Add-History.

Add-History
shell

13. Out-File

To save the output of your Pow­er­Shell commands on your computer, use the Out-File cmdlet. This stores the Pow­er­Shell commands in a raw text file under the specified path.

Get-Process | Out-File -FilePath .\Process.txt
shell

14. Copy-Item

In Pow­er­Shell, you can also copy elements and save the copy in a different location. Use the Copy-Item command and specify the directory in which the copy is to be saved. This works as follows:

Copy-Item "C:\folder1\file.txt" -Destination "C:\folder2"
shell

15. Get-ChildItem

You can utilize the Get-ChildItem command to fetch items from one or more storage locations. If there are sub-elements, they will also be displayed. This command lists at­trib­ut­es, the timestamp of the last change, the file size, and the element’s name by default. If a storage location is empty, the output is omitted.

Get-ChildItem -Path C:\example
shell

The at­trib­ut­es are shown beneath the “Mode” line. The following prop­er­ties are common:

  • a (archive)
  • d (directory)
  • h (hidden)
  • l (link)
  • r (read-only)
  • s (system)

16. Set-Au­then­ti­codeS­ig­na­ture

To protect your files, you can equip them with an Au­then­ti­code signature using the Set-Au­then­ti­codeS­ig­na­ture command. However, this only works for files that support the Subject Interface Package (SIP).

$cert=Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
Set-AuthenticodeSignature -FilePath PsTestInternet2.ps1 -Certificate $cert
shell

17. Invoke-Item

To perform the standard action as­so­ci­at­ed with a specific file, Invoke-Item provides the simplest method. This command ensures, for instance, that an ex­e­cutable file is executed directly or that a document file is opened in the default ap­pli­ca­tion. In this example, the file is opened in Microsoft Word by default:

Invoke-Item "C:\Test\example.doc"
shell

18. Start-Job

To initiate a back­ground job on your local computer, you can use the ap­pro­pri­ate command for this purpose. Start-Job allows you to execute a specific command in the back­ground, without in­ter­act­ing with the current session.

Start-Job -ScriptBlock { Get-Process -Name pwsh }
shell
Dedicated Servers
Per­for­mance through in­no­va­tion
  • Dedicated en­ter­prise hardware
  • Con­fig­urable hardware equipment
  • ISO-certified data centers

Perform actions with these Pow­er­Shell commands

While the earlier Pow­er­Shell commands were primarily focused on providing overviews, you can also perform various actions using the ap­pro­pri­ate cmdlets, thus enhancing your system’s pro­duc­tiv­i­ty. The following Pow­er­Shell commands stream­line your workflow.

19. Clear-Content

To erase the content of an element while pre­serv­ing the element itself, the Clear-Content command is the ideal choice. An example of its use would be clearing the text from a document while leaving the actual file intact. The process is executed as follows:

Clear-Content C:\Temp\example.txt
shell

20. ForEach-Object

The ForEach-Object command allows you to perform an operation across all elements in a col­lec­tion of input objects. In this example, we divide three integers in an array by 10:

10000, 1000, 100 | ForEach-Object -Process {$_/10}
1000
100
10
shell

21. Compare-Object

To avoid the manual com­par­i­son of different sets of objects, you can employ the Compare-Object cmdlet. This command generates a report high­light­ing the dis­tinc­tions between the records. The first record serves as the reference object, and the second record as the dif­fer­ence object. You can specify which factors to compare, and if this in­for­ma­tion is omitted, only the string results will be compared. The output is divided into prop­er­ties that only appear in the reference object (<==) and prop­er­ties that only appear in the dif­fer­ence object (==>). In this example, document1.txt contains the values Berlin, London and Paris. Document2.txt contains Berlin, Vienna and Amsterdam.

Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Document1.txt) -DifferenceObject (Get-Content -Path C:\Test\Document2.txt)
InputObject	SideIndicator
---------------	-----------------
Wien		==>
Amsterdam	==>
London		<==
Paris		<==
shell

Content that appears in both documents (in this case “Berlin”) is not displayed by default.

22. New-Object

One of the most useful Pow­er­Shell commands is New-Object. You can utilize this cmdlet to in­stan­ti­ate an object from the .NET framework or a Component Object Model (COM). For instance, if you intend to create a System.Version object with “1.2.3.4” as the con­struc­tor string, the command is executed as follows:

New-Object -TypeName System.Version -ArgumentList "1.2.3.4"
shell

23. Select-Object

Use the Select-Object command to select an object or a group of objects that have the prop­er­ties you have defined. The pa­ra­me­ters that you can specify for this are as follows:

  • First
  • Last
  • Unique
  • Skip
  • Index

In the following example, we use the Pow­er­Shell commands Get-Process and Sort-Object to display the three processes with the highest memory con­sump­tion at the time of input.

Get-Process | Sort-Object -Property WS | Select-Object -Last 3
shell

24. Set-Alias

Windows shortcuts are useful to execute actions even faster. Pow­er­Shell also offers this option. You can use the Set-Alias cmdlet to define a shortcut for different Pow­er­Shell commands. In the following example, we create the alias “ci” for the Get-ChildItem command for the current session.

PS> Set-Alias -Name ci -Value Get-ChildItem
PS> Get-Alias -Name ci
shell

25. Set-Location

To change the working memory location, use the Set-Location command. Possible new locations are di­rec­to­ries, sub­di­rec­to­ries, registry locations or provider paths. In the following example, we specify the C: drive as the current storage location:

PS C:\Windows\> Set-Location HKLM:\
PS HKLM:\> Set-Location C:
PS C:\Windows\>
shell

26. Set-Service

You can use the Set-Service cmdlet to interact with a service and start, stop or pause it. It’s also possible to change the prop­er­ties of the service. In the following example, we change the display name of a service from “New Work­sta­tion” to “Old Work­sta­tion”.

Set-Service -Name New Workstation -DisplayName "Old Workstation"
shell

27. Set-TimeZone

To change the time zone of your system, the Set-TimeZone command is the right choice. To set the co­or­di­nat­ed universal time as the new system time, use this command:

Set-TimeZone -Id "UTC"
shell

28. Restart-Computer

You can restart the operating system on your local computer or a remote computer using the ap­pro­pri­ate Pow­er­Shell command called Restart-Computer. It can be executed as follows:

For your local computer:

Restart-Computer
shell

For select computers in your network:

Restart-Computer -ComputerName Server01, Server03
shell

29. Restart-Service

To stop and restart a service using Pow­er­Shell commands, Restart-Service is the ap­pro­pri­ate cmdlet. For example, you can restart all services that begin with “Net”:

PS C:\> Restart-Service -DisplayName "net*"
shell

30. Clear-Re­cy­cleBin

The recycle bin should be emptied regularly, which is also possible via Pow­er­Shell. The command is Clear-Re­cy­cleBin.

Clear-RecycleBin
shell

31. Get-Com­put­er­In­fo

The Get-Com­put­er­In­fo command is used to retrieve system and operating system prop­er­ties.

Get-ComputerInfo
shell

32. Move-Item

When you need to relocate an item from one location to another, there are several Pow­er­Shell commands at your disposal. Nev­er­the­less, the most fre­quent­ly used option is Move-Item. In this example, we are moving the old.txt file from the C: drive to the D:\Temp directory while also renaming it to new.txt.

Move-Item -Path C:\old.txt -Destination D:\Temp\new.txt
shell

Mon­i­tor­ing and debugging with the ap­pro­pri­ate Pow­er­Shell commands

Pow­er­Shell commands that enable system mon­i­tor­ing and checking are ex­cep­tion­al­ly valuable, es­pe­cial­ly when testing a new network’s per­for­mance under realistic con­di­tions. The following Pow­er­Shell commands are par­tic­u­lar­ly useful for these purposes.

33. Debug-Process

Debugging is an important process to ensure that all settings and processes run without errors. To do this, you need to download and configure the ap­pro­pri­ate debuggers. Once this is done, use the Debug-Process command. In the following example, we use a debugger for the Explorer:

PS C:\> Debug-Process -Name "Explorer"
shell

To debug several processes si­mul­ta­ne­ous­ly, simply subdivide them using commas.

34. Enable-PS­Break­point

To activate certain break­points, use the Enable-PS­Break­point command. This sets the value of the cmdlet to “true” from a technical per­spec­tive. Use these Pow­er­Shell commands to activate all break­points in the current session:

Get-PSBreakpoint | Enable-PSBreakpoint
shell

Use this command to activate break­points using their ID:

Enable-PSBreakpoint -ID 0, 3, 4
shell

35. Disable-PS­Break­point

To de­ac­ti­vate Pow­er­Shell break­points again, the suitable cmdlet for this purpose is Disable-PS­Break­point. Tech­ni­cal­ly speaking, the value of the Enable-PS­Break­point command is set to “false”. To de­ac­ti­vate a break­point with the ID 0, enter the following:

Disable-PSBreakpoint -Id 0
shell

36. Get-Counter

For Windows devices, you can retrieve their per­for­mance data using Pow­er­Shell. The suitable command for this task is Get-Counter, which can be used for both your local computer and remote computers. In the following example, we are re­triev­ing data from the local computer:

Get-Counter -ListSet *
shell

37. Start-Sleep

Pausing a script or session can be crucial, es­pe­cial­ly during system overload sit­u­a­tions. Pow­er­Shell provides the Start-Sleep command for this purpose, allowing you to specify the duration for which ac­tiv­i­ties should be paused. In the following example, execution pauses for two seconds:

Start-Sleep -Seconds 2
shell

38. Test-Path

Use the Test-Path command to check whether all elements of a specific path are present. The possible results are “True” or “False”.

Test-Path -Path "C:\Documents and Settings\user"
False
shell

39. Test-Con­nec­tion

You can also assess network con­nec­tiv­i­ty within your network using Pow­er­Shell. This is achieved by sending ICMP echo request packets to specified re­cip­i­ents through the Test-Con­nec­tion command, which solicits responses via the Internet Control Message Protocol (ICMP). In our example, we send a request to Server02 via the IPv6 protocol.

Test-Connection -TargetName Server02 -IPv6
shell

40. Get-WinEvent

When you need to view one or more event logs, there are various Pow­er­Shell commands at your disposal. The most practical cmdlet for this purpose is Get-WinEvent. To retrieve all logs from your local computer, you can use the following command:

Get-WinEvent -ListLog *
shell
Go to Main Menu