Useful Commands For PowerShell – 15 Cmdlets Examples

In this guide, we want to discuss Useful Commands For PowerShell and explore Cmdlets examples on Windows. Cmdlets, or Command-lets, in PowerShell, are specialized commands designed to perform specific tasks within the PowerShell environment. They are essentially lightweight commands that follow a Verb-Noun naming convention, such as Get-Process or Start-Service.

Here we try to provide some useful cmdlets in PowerShell that everyone must know about it. To get familiar with them, proceed to the following steps.

Learn 15 Useful Commands For PowerShell – PowerShell Cmdlets Examples

To learn Useful Commands For PowerShell, you must log in to your Windows system and Run your PowerShell as an Administrator. Then, follow the steps below to get familiar with the most useful commands for PowerShell.

1 – Get-Process PowerShell Cmdlet

This command will display a list of processes that are running on your system. For example:

Get-Process PowerShell Cmdlet

2 – Get-Service PowerShell Cmdlet

If you want to display all services’s status on your system, you can use the Get-Service command in PowerShell. For example:

Get-Service PowerShell Cmdlet

3 – Start-Service Command in PowerShell

Also, you can easily start a service on your system by using the PowerShell commands. To do this, you can use the Start-Service command. For example, we start a service named BITS:

Start-Service -Name "BITS"
Start-Service Command in PowerShell

4 – Stop-Service Cmdlet

As the name of the command shows, it can be used to stop a service from PowerShell. For example, to stop the BITS service, you can run:

Stop-Service -Name "BITS"

5 – The Useful Get-ChildItem Command

This amazing cmdlet lists the files and folders in a specified location. For example, to list the files and folders in drive C, you can run:

Get-ChildItem "C:\"
The Useful Get-ChildItem Command

6 – Create a New File with New-Item Cmdlet

With this PowerShell Cmdlet, you can easily create a new file or folder on your system. For example, we create a new file in the following path in our system:

New-Item -Path "C:\example.txt"
Create a New File with New-Item

7 – Remove a File with Remove-Item Cmdlet

Also, you can simply remove files and folders via PowerShell by using the Remove-Item command. For example:

Remove-Item -Path "C:\example.txt"

8 – Copy Files with Copy-Item Cmdlet

To copy files using the Copy-Item cmdlet in PowerShell, you can use the following syntax:

Copy-Item -Path "source_path" -Destination "destination_path"

If you want to copy an entire directory and its contents recursively, you can add the -Recurse parameter:

Copy-Item -Path "C:\source\directory" -Destination "D:\destination" -Recurse

9 – The Move-Item Cmdlet in PowerShell

This is used to move files or directories from one location to another. Its syntax is similar to Copy-Item, but instead of copying, it moves the specified item.

Move-Item -Path "source_path" -Destination "destination_path"

Similarly, if you want to move an entire directory and its contents recursively, you can add the -Recurse parameter:

Move-Item -Path "C:\source\directory" -Destination "D:\destination" -Recurse

10 – Get-Content Cmdlet To View File’s Content

You can easily display your file’s content without using a text editor from PowerShell. For example, we have an example text file and view its content with the command below:

Get-Content -Path "C:\example.txt"
Get-Content To View File's Content

11 – Clear-Content Cmdlet

If you want to delete the contents of a file without deleting the file itself, you can use the Clear-Content command in PowerShell. For example, to clear the content of the following file, we use:

Clear-Content -Path "C:\example.txt"

Once you check the content of the file, it will be empty.

12 – The Set-ExecutionPolicy Cmdlet in PowerShell

This Cmdlet is used to determine the policy for executing scripts on a system. It sets the execution policy for the current PowerShell session or the entire system. For example, to set the execution policy to RemoteSigned for the current user, you can run:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

To set the execution policy to Unrestricted for the entire machine (which may not be recommended for security reasons), you can run:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force

13 – Display Executed Commands in PowerShell

To get a history of your executed commands, you can simply use the Get-History Cmdlet:

Display Executed Commands

14 – List PowerShell Commands

The Get-Command cmdlet in PowerShell is used to receive information about cmdlets, functions, workflows, aliases, and scripts available in PowerShell. It helps users discover what commands are available and provides details about their usage.

List PowerShell Commands

15 – Get-Help Cmdlet

This command provides users with detailed documentation and usage instructions for these commands. For example, to get basic help information about the Get-Service cmdlet, you can run:

Get-Help Get-Service
get basic help information PowerShell

To get detailed help information, including examples, you can run:

Get-Help Get-Service -Detailed
get detailed help information PowerShell

That’s it, these are the most useful Cmdlets in PowerShell that everyone must know about.

Conclusion

In conclusion, learning PowerShell can increase your efficiency and productivity in Windows system administration and automation tasks. In this guide, we’ve covered 15 useful commands for PowerShell. By learning these commands and their usage, you can improve your PowerShell skills. Hope you enjoy it.

Also, you may like to read the following articles:

Learn Essential Windows CMD Commands

Work with Windows 11 Terminal

Windows 11 Linux Compatibility Sudo Command

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!