What are PowerShell commands? The 40 most important commands at a glance

Leveraging the appropriate PowerShell commands lets you employ modules with precision. These well-organised cmdlets can be further tailored through optional parameters. We present the 40 most essential PowerShell commands so that you can work optimally in your system or network.

What is a PowerShell command?

PowerShell, which comes preinstalled since Windows 7, allows you to enter PowerShell 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 understood by PowerShell itself. These cmdlets consist of a verb and a noun, which are separated by a hyphen. Additionally, you can enhance these PowerShell commands with optional parameters, separated by spaces. PowerShell’s utility extends beyond administrators; it also proves invaluable in the realm of development. With a plethora of pre-installed PowerShell commands available, we acquaint you with the most pivotal ones.

The most important PowerShell commands

PowerShell commands allow you to carry out extensive admin tasks in just a few entries. Among the basic commands that you’ll likely use most frequently are those that offer an initial overview of your network’s structure, list other PowerShell commands, assist in essential security configurations, and enable valuable analyses. Here are some of the most crucial PowerShell commands you should be familiar with:

1. Get-Module -All

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

Get-Module -All
shell

2. Get-Command

There is an abundance of pre-defined PowerShell commands. To obtain an overview of the currently available PowerShell commands, simply use the Get-Command command. This command will neatly list all potential actions and offer concise explanations for each respective cmdlet. This holds true even if you have installed additional modules.

Get-Command
shell

3. Get-Help

The Get-Command list described above provides an initial overview; for more detailed information 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 information. 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 applications, programs, and processes on your system, you can use the Get-Process command. If you specify a particular application, you’ll receive additional information about that specific application.

Get-Process
shell

5. Get-Service

The Get-Service command functions similarly to the Get-Process cmdlet. However, it distinguishes itself by offering information about all active services. If you wish to obtain information about a particular service or a specific category of services, you can easily specify your request.

Get-Service
shell

6. Stop-Process

You can also use various PowerShell commands to stop processes via the shell. One option is the Stop-Process command. You define the corresponding process by name, ID or with other attributes. Here’s an example:

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

A confirmation of the command is requested with -Confirm. The -PassThru command requests confirmation of the stopped process. This is not done automatically.

7. ConvertTo-HTML

To swiftly identify problems or potential complications, having a clear display is incredibly beneficial. You can achieve this by utilising the ConvertTo-HTML command, which transfers the output of your PowerShell commands into an HTML file. This presents the information 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 representation 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 information than you require. By using Where-Object in conjunction with a pipe, you can display only the specific information 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 PowerShell commands that you’ve entered during a session, Get-History is the right cmdlet. To list all PowerShell commands:

Get-History
shell

With this specification, you only call the last ten PowerShell commands:

Get-History -Count 10
shell

11. Clear-History

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

Clear-History
shell

To delete select PowerShell commands, simply add the corresponding parameters. The following input removes all PowerShell commands that contain ‘Help’ or end with ‘Syntax’.

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

12. Add-History

It’s also possible to add PowerShell commands to a session. This allows you to call them up again later on. The appropriate cmdlet is Add-History.

Add-History
shell

13. Out-File

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

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

14. Copy-Item

In PowerShell, 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 attributes, 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 attributes are shown beneath the ‘Mode’ line. The following properties are common:

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

16. Set-AuthenticodeSignature

To protect your files, you can equip them with an Authenticode signature using the Set-AuthenticodeSignature 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 associated with a specific file, Invoke-Item provides the simplest method. This command ensures, for instance, that an executable file is executed directly or that a document file is opened in the default application. 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 background job on your local computer, you can use the appropriate command for this purpose. Start-Job allows you to execute a specific command in the background, without interacting with the current session.

Start-Job -ScriptBlock { Get-Process -Name pwsh }
shell
Dedicated Server
Performance through innovation
  • Enterprise hardware
  • Power and flexibility
  • Latest security technology

Perform actions with these PowerShell commands

While the earlier PowerShell commands were primarily focused on providing overviews, you can also perform various actions using the appropriate cmdlets, thus enhancing your system’s productivity. The following PowerShell commands streamline your workflow.

19. Clear-Content

To erase the content of an element while preserving 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 collection 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 comparison of different sets of objects, you can employ the Compare-Object cmdlet. This command generates a report highlighting the distinctions between the records. The first record serves as the reference object, and the second record as the difference object. You can specify which factors to compare, and if this information is omitted, only the string results will be compared. The output is divided into properties that only appear in the reference object (<==) and properties that only appear in the difference 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 PowerShell commands is New-Object. You can utilise this cmdlet to instantiate 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 constructor 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 properties you have defined. The parameters that you can specify for this are as follows:

  • First
  • Last
  • Unique
  • Skip
  • Index

In the following example, we use the PowerShell commands Get-Process and Sort-Object to display the three processes with the highest memory consumption 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. PowerShell also offers this option. You can use the Set-Alias cmdlet to define a shortcut for different PowerShell 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 directories, subdirectories, 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 properties of the service. In the following example, we change the display name of a service from ‘New Workstation’ to ‘Old Workstation’.

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 coordinated 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 appropriate PowerShell 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 PowerShell commands, Restart-Service is the appropriate cmdlet. For example, you can restart all services that begin with ‘Net’:

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

30. Clear-RecycleBin

The recycle bin should be emptied regularly, which is also possible via PowerShell. The command is Clear-RecycleBin.

Clear-RecycleBin
shell

31. Get-ComputerInfo

The Get-ComputerInfo command is used to retrieve system and operating system properties.

Get-ComputerInfo
shell

32. Move-Item

When you need to relocate an item from one location to another, there are several PowerShell commands at your disposal. Nevertheless, the most frequently 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

Monitoring and debugging with the appropriate PowerShell commands

PowerShell commands that enable system monitoring and checking are exceptionally valuable, especially when testing a new network’s performance under realistic conditions. The following PowerShell commands are particularly 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 appropriate 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 simultaneously, simply subdivide them using commas.

34. Enable-PSBreakpoint

To activate certain breakpoints, use the Enable-PSBreakpoint command. This sets the value of the cmdlet to ‘true’ from a technical perspective. Use these PowerShell commands to activate all breakpoints in the current session:

Get-PSBreakpoint | Enable-PSBreakpoint
shell

Use this command to activate breakpoints using their ID:

Enable-PSBreakpoint -ID 0, 3, 4
shell

35. Disable-PSBreakpoint

To deactivate PowerShell breakpoints again, the suitable cmdlet for this purpose is Disable-PSBreakpoint. Technically speaking, the value of the Enable-PSBreakpoint command is set to ‘false’. To deactivate a breakpoint with the ID 0, enter the following:

Disable-PSBreakpoint -Id 0
shell

36. Get-Counter

For Windows devices, you can retrieve their performance data using PowerShell. 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 retrieving data from the local computer:

Get-Counter -ListSet *
shell

37. Start-Sleep

Pausing a script or session can be crucial, especially during system overload situations. PowerShell provides the Start-Sleep command for this purpose, allowing you to specify the duration for which activities 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-Connection

You can also assess network connectivity within your network using PowerShell. This is achieved by sending ICMP echo request packets to specified recipients through the Test-Connection 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 PowerShell 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
Was this article helpful?
Page top