The 16 Best PowerShell Commands (Cmdlet) You Need to Know

Most of us prefer PowerShell because of its automation capabilities. It is a command line shell with a fully developed scripting language. You can use the built-in cmdlets or write your own script to automate administrative tasks for Windows and other compatible operating systems. It lets you do everything you can do with GUI apps and more.


However, mastering PowerShell’s functionality and flexibility involves a steep learning curve. If you’re new to PowerShell, here are the essential commands you can learn to master this scripting language long term.


1. Get help

Acquire help, as its name suggests, is part of PowerShell’s built-in help system. It helps you find the necessary information for the command, concepts and functions, identify aliases, scripts, etc.

To get help on a PowerShell cmdlet, you must use the Get-help cmdlet followed by a cmdlet name. For example, to view the synopsis and associated syntaxes for the get-process cmdlet, type:

Get-Help Get-Process

This command can read both comment-based and XML-based help provided by the function author.

Alternatively, you can use the Get help online command to get online help for a PowerShell cmdlet. For example, to view Microsoft’s online documentation for the Get content cmdlet, type:

Get-Help Get-Content -online

2. Get-process

The get-process The command helps you retrieve and display a list of all active system processes with their identifiers (IDs). You can use it as an effective alternative to Windows Task Manager to view, stop and restart system processes.

For example, if you need to stop the GameBar process, you must first find the process ID associated with it. So type:

Get-Process

This command will show all running system processes. Next, find the ID associated with the process you want to stop. To stop the process, type:

Get-Process -ID 20496 | Stop-Process

here -ID 20496 is the process ID (GameBar) you want to stop.

3. Boot process

You can use the Start the process Cmdlet in PowerShell to start one or more processes on a local computer. To use the cmdlet, type Start-Process followed by the name of the process. For example, if you want to start a new Notepad process, type:

Start-Process notepad 

Additionally, you can use Start-Process parameters to specify options. For example, if you need to run a process as administrator, type:

Start-Process -FilePath "notepad" -Verb runAs

4. Get-Command

The Get-Command allows you to view all PowerShell commands installed on your computer. Similar to Get-Help, you can use Get-Command followed by a search query to find commands for a specific feature.

Since Get-Command displays all commands, you can specify parameters to find features with a specific command name and type. For example, to search for cmdlets (CommandTypes) beginning with A (Name), type:

Get-Command -Name A* -CommandType cmdlet

Otherwise, type Get-Help Get-Command – Examples to see more examples.

5. Get-Service

The Get-Service cmdlet allows you to view your computer status and list of services. By default, the Get-Service command returns all services (stopped and running).

You can use the parameters to specify and search for services based on their status, name, and dependent services. For example, to display all services beginning with the name Win, type:

Get-Service -Name "Win*"

6. Get-ChildItem

You can use PowerShell to search directories. The Get-ChildItem The command is a handy cmdlet for finding folders and files and quickly performing content-based searches without using File Explorer.

To display all top-level folders in the C: directory, type:

Get-ChildItem "C:"

Additionally, use the -Path parameter to display a particular folder, subfolders and content. For example, to display all subfolders and files in the Programs Files folder, type:

Get-ChildItem -Path "C:Program Files"

Also, use the –Recurse parameter to show all files in the specified folder and the -Last name parameter to display item names in a directory.

Get-ChildItem -Path "C:Program FilesFodler_Name" -Recurse | Select FullName

In the command above, replace subfolder with the name of the folder to display its contents.

7. Copy item

The Copy item cmdlet allows you to copy-paste files and folders and their contents into another directory. To copy files and folders, type Copy item source tracking –Path, -Destination parameter and the destination address. For example, to copy E:Folder1 and its contents to E:Folder2type:

Copy-Item "E:Folder1" -Destination "E:Folder2" -Recurse

Note that the -Recursive The parameter in the above command is responsible for moving all the contents of the folder. Without this, PowerShell will only copy the top level folder (Folder1) and files specified in the command.

8. Move element

Similarly, to move an element, you can use the Move Item cmdlet. For example, to move the folder, files, subfolders, and all of its contents to the destination you specified, type:

Move-Item -Path "E:Folder1" -Destination "E:Folder2" 

9. Delete Item

The Remove the object The cmdlet allows you to delete files, folders, functions, and other data types from the specified directory. For example, to delete the Test.txt file in the E:Folder1 folder, type:

Remove-Item E:Folder1Test.txt

10. Get Content

The Get content The cmdlet allows you to display the content of an element without using a text editor. For example, to retrieve the contents of the Test.txt file, type:

Get-Content "E:Folder1Test.txt"

You can further specify the length of content to display using the -The total account setting.

11. Clear content

You can use the Clear content Cmdlet to delete the contents of a specified file without deleting the file itself. Useful for automating tasks where you have a hardcoded filename but want to have a clean file each time the script is run.

To test the command, create a text file with content. Then type:

Clear-Content -Path "E:Folder1Test1.txt"

This will delete the contents of the file without deleting the file.

12. Set-ExecutionPolicy

The default execution policy in PowerShell is set to Restricted. This prevents the execution of malicious scripts in the PowerShell environment. However, when you run a local PowerShell script, you may encounter runtime script is disabled on this system error.

The Set-ExecutionPolicy Cmdlets let you change security levels for running scripts. To find your current execution policy, type:

Get-ExecutionPolicy

If you need to run an unsigned script, in an elevated PowerShell prompt, type:

 Set-ExecutionPolicy RemoteSigned

Other valid Set-ExecutionPolicy values ​​include Limit, AllSignedand Free.

13. Set-Location

By default PowerShell uses C:UsersUsername as the default working directory. The Set-Location The cmdlet allows you to set the current working directory to a specified location. Useful if you want to run a script or command from a specific location without having to specify the path each time.

For example, to set C:UsersUsernameDocuments as the current working directory, type:

Set-Location "C:UsersusrenameDocuments"

This is a temporary measure as PowerShell will reset the working directory to its default after reboot.

14. Export-CSV

If you want to export and present the PowerShell output in a more organized way, you can use the Export-CSV cmdlet. It takes the output file of the specified command and converts it to a CSV file.

To test the command, try the following command:

Get-Process | Export-CSV PSprocess.csv

The above command will create a psporcess.csv file with all data of active processes.

15. Convert to HTML

If you prefer to create an HTML report, you can use the ConvertTo-HTML Cmdlet. To create an HTML report for all running processes on your PC, type:

Get-Process | ConvertTo-HTML > PSprocess.html

In the above command, psprocess is the name of the export file, and HTML is the extension. You can access the exported HTML file in the current working directory located at C:Usersusername.

16. Get History

You can use the Up down arrow key to scroll through recently executed commands in PowerShell. However, to view a list of all recently executed commands in your current session at once, you can use the Get history cmdlet.

It will display a list of all recently executed commands along with their IDs. Useful if you want to view the full context of previously executed commands. To do this, type:

Get-History Id | fl

For example, to view execution details such as status, start and end time, and duration of the third command, type:

get-history 3 | fl, 

To run any command in the list again, type:

Invoke-History followed by the command id

For instance, type Summon History 3 to restart a previously executed command without typing it again.

Additionally, use Clear story to clear the history of the current session.

Now that you have a basic idea of ​​PowerShell commands, go ahead and explore our guide on the best PowerShell cmdlets to improve your Windows admin skills. Here you can learn how to work with data using cmdlets, format tables and lists, and a quick overview of the Get-Member command.

PowerShell commands to streamline your tasks

PowerShell is known for its automation capabilities. It can help you automate hundreds of activities in your development work to save time and improve productivity.

Although we’ve only covered the basic commands, try exploring the syntax, aliases, and variables, functions available on many of these commands to master this highly efficient scripting language.

Comments are closed.