Lever­aging the ap­pro­pri­ate Power­Shell commands lets you employ modules with precision. These well-organised cmdlets can be further tailored through optional para­met­ers. We present the 40 most essential Power­Shell commands so that you can work optimally in your system or network.

What is a Power­Shell command?

Power­Shell, which comes pre­in­stalled since Windows 7, allows you to enter Power­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 Power­Shell itself. These cmdlets consist of a verb and a noun, which are separated by a hyphen. Ad­di­tion­ally, you can enhance these Power­Shell commands with optional para­met­ers, separated by spaces. Power­Shell’s utility extends beyond ad­min­is­trat­ors; it also proves in­valu­able in the realm of de­vel­op­ment. With a plethora of pre-installed Power­Shell commands available, we acquaint you with the most pivotal ones.

The most important Power­Shell commands

Power­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­quently are those that offer an initial overview of your network’s structure, list other Power­Shell commands, assist in essential security con­fig­ur­a­tions, and enable valuable analyses. Here are some of the most crucial Power­Shell commands you should be familiar with:

1. Get-Module -All

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

Get-Module -All
shell

2. Get-Command

There is an abundance of pre-defined Power­Shell commands. To obtain an overview of the currently available Power­Shell commands, simply use the Get-Command command. This command will neatly list all potential actions and offer concise ex­plan­a­tions for each re­spect­ive 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­form­a­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­form­a­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­plic­a­tions, programs, and processes on your system, you can use the Get-Process command. If you specify a par­tic­u­lar ap­plic­a­tion, you’ll receive ad­di­tion­al in­form­a­tion about that specific ap­plic­a­tion.

Get-Process
shell

5. Get-Service

The Get-Service command functions similarly to the Get-Process cmdlet. However, it dis­tin­guishes itself by offering in­form­a­tion about all active services. If you wish to obtain in­form­a­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 Power­Shell commands to stop processes via the shell. One option is the Stop-Process command. You define the cor­res­pond­ing process by name, ID or with other at­trib­utes. Here’s an example:

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

A con­firm­a­tion of the command is requested with -Confirm. The -PassThru command requests con­firm­a­tion of the stopped process. This is not done auto­mat­ic­ally.

7. ConvertTo-HTML

To swiftly identify problems or potential com­plic­a­tions, having a clear display is in­cred­ibly be­ne­fi­cial. You can achieve this by utilising the ConvertTo-HTML command, which transfers the output of your Power­Shell commands into an HTML file. This presents the in­form­a­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­res­ent­a­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­form­a­tion than you require. By using Where-Object in con­junc­tion with a pipe, you can display only the specific in­form­a­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 Power­Shell commands that you’ve entered during a session, Get-History is the right cmdlet. To list all Power­Shell commands:

Get-History
shell

With this spe­cific­a­tion, you only call the last ten Power­Shell commands:

Get-History -Count 10
shell

11. Clear-History

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

Clear-History
shell

To delete select Power­Shell commands, simply add the cor­res­pond­ing para­met­ers. The following input removes all Power­Shell commands that contain ‘Help’ or end with ‘Syntax’.

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

12. Add-History

It’s also possible to add Power­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 Power­Shell commands on your computer, use the Out-File cmdlet. This stores the Power­Shell commands in a raw text file under the specified path.

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

14. Copy-Item

In Power­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 utilise 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­utes, 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­utes 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­ticodeS­ig­na­ture

To protect your files, you can equip them with an Au­then­ticode signature using the Set-Au­then­ticodeS­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­ated with a specific file, Invoke-Item provides the simplest method. This command ensures, for instance, that an ex­ecut­able file is executed directly or that a document file is opened in the default ap­plic­a­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 Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

Perform actions with these Power­Shell commands

While the earlier Power­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­ductiv­ity. The following Power­Shell commands stream­line your workflow.

19. Clear-Content

To erase the content of an element while pre­serving 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­is­on 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­form­a­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 Power­Shell commands is New-Object. You can utilise 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­struct­or 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 para­met­ers that you can specify for this are as follows:

  • First
  • Last
  • Unique
  • Skip
  • Index

In the following example, we use the Power­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. Power­Shell also offers this option. You can use the Set-Alias cmdlet to define a shortcut for different Power­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 dir­ect­or­ies, sub­dir­ect­or­ies, 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­ordin­ated 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 Power­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 Power­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­cycleBin

The recycle bin should be emptied regularly, which is also possible via Power­Shell. The command is Clear-Re­cycleBin.

Clear-RecycleBin
shell

31. Get-Com­pu­ter­Info

The Get-Com­pu­ter­Info 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 Power­Shell commands at your disposal. Nev­er­the­less, the most fre­quently 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­it­or­ing and debugging with the ap­pro­pri­ate Power­Shell commands

Power­Shell commands that enable system mon­it­or­ing and checking are ex­cep­tion­ally valuable, es­pe­cially when testing a new network’s per­form­ance under realistic con­di­tions. The following Power­Shell commands are par­tic­u­larly 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 sim­ul­tan­eously, 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­spect­ive. Use these Power­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­tiv­ate Power­Shell break­points again, the suitable cmdlet for this purpose is Disable-PS­Break­point. Tech­nic­ally speaking, the value of the Enable-PS­Break­point command is set to ‘false’. To de­ac­tiv­ate 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­form­ance data using Power­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­cially during system overload situ­ations. Power­Shell provides the Start-Sleep command for this purpose, allowing you to specify the duration for which activ­it­ies 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­nectiv­ity within your network using Power­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 Power­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