Janna Theme License is not validated, go to the theme options page to validate the license, you need a single license for each domain name.

16 Essential PowerShell Commands You Should Know

Windows PowerShell is a powerful application based on the .NET framework. It relies on PowerShell commands called cmdlets. By combining them in a specific order, you can perform almost any operation from a PowerShell window. To explain how they work, we've included a brief list of the most basic PowerShell commands.

Featured-Top-Essential-PowerShell-Commands.jpg 16 Essential PowerShell Commands You Should Know

Good to know: Windows cannot find “Powershell.exe”Find out what to do to get it back.

How to use PowerShell commands

To start using cmdlets, you need to: Run PowerShell in Administrator mode of Search menu.

Essential-PowerShell-Commands-Administrator-PowerShell-Search.jpg 16 Essential PowerShell Commands You Should Know

Basic PowerShell Commands

PowerShell in Windows is not only a powerful command-line interface, but also a scripting and programming window that can launch any application or process you want. While there are several hundred cmdlets, to get started, you only need to learn the most important ones.

1. Clear-Host or Cls

Did you make a serious mistake while writing, or is something not going as planned? Fortunately, there are plenty of tasks in PowerShell. It can be ordered clear-host It's easy to erase all text from the screen. Simply type the command on any line on your screen, and everything will disappear instantly.

Essential-PowerShell-Commands-Clear-Host-800x383.jpg 16 Essential PowerShell Commands You Should Know

You can also use the simpler command: class , which is frequently used in the command prompt, with PowerShell. These two plain text commands come in handy when you encounter an error message.

Essential-PowerShell-Commands-Cls-800x364.jpg 16 Essential PowerShell Commands You Should Know

To avoid typing errors in the Command Prompt or PowerShell window, copy and paste commands to improve efficiency.

2. Convert-to-HTML

Having a large HTML string is more aesthetically pleasing than glancing at cluttered PowerShell screenshots. It's also useful when you need to share script errors and other PowerShell events with non-technical team members.

All PowerShell components use .NET objects that we can view on the PowerShell screen. To view them in a full browser window, use the Convert to HTML cmdlet. Below is an example of viewing all PowerShell aliases on the web. Remember to use a separate line before "Recall item".

Get-Alias | ConvertTo-Html | Out-File aliases.htm Invoke-Item aliases.htm

Essential-PowerShell-Commands-Convert-to-HTML-800x363.jpg 16 Essential PowerShell Commands You Should Know

Once you run the HTML conversion command, PowerShell will prompt you to open the output file using another application. Using a browser will generate a list of items, such as aliases.

Essential-PowerShell-Commands-Aliaes-on-Web-Browser-800x430.jpg 16 Essential PowerShell Commands You Should Know

3. Get-Command

There are two basic types of commands: aliases and functions. PowerShell aliases act as a title for a function or cmdlet. Windows stores some aliases by default, which you can retrieve using Get-Command. You can also create your own nicknames.

Essential-PowerShell-Commands-get-command-Aliases-800x535.jpg 16 Essential PowerShell Commands You Should Know

Another type of command in PowerShell is functions. These use a supported verb (such as “get”) and a simple name (such as “StorageNode”).

Also read:  Top 7 Ways to Fix Steam Streaming Not Working on Windows 11

Essential-PowerShell-Commands-Get-command-Functions-800x483.jpg 16 Essential PowerShell Commands You Should Know

We use the function "Object Selection" (Note the verb-noun combination) with what is known as the computername environment variable to display the name of the local computer.

$env:computername | Select-Object

Essential-PowerShell-Commands-Getting-Computer-Name-Function.jpg 16 Essential PowerShell Commands You Should Know

Functions are the starting point for advanced PowerShell coding. You can use functions, such as starting a process, with parameters and variables toCreate your own batch scripts, And perform a series of tasks.

4. Get-Help

PowerShell has its own cmdlet for self-learning troubleshooting, Get Help , which displays all quick fixes and help articles in one window. Enter the command at the end of any output for help with different modules. You may need to press Y To allow updated versions of help content.

Essential-PowerShell-Commands-Updating-on-GetHelp-800x413.jpg 16 Essential PowerShell Commands You Should Know

There are many help options available via Get help. For example, if you want to know what the Get operation does and what its exact syntax is, enter the following:

Get-Help Get-Process

Essential-PowerShell-Commands-Get-Help-Examples-800x474.jpg 16 Essential PowerShell Commands You Should Know

Tip: Are you worried about a keylogger monitoring your computer activity? Find out. How to detect a keylogger on Windows.

5. Get-Process

Get-Process It is a basic PowerShell command that schedules the entire list of processes on your local or remote computer.

Essential-PowerShell-Commands-Get-Process-800x521.jpg 16 Essential PowerShell Commands You Should Know

For more detailed information about the process, you will need to specify other parameters, such as the process identifier (PID) or the process name.

Essential-PowerShell-Commands-Specific-Process-Name-800x467.jpg 16 Essential PowerShell Commands You Should Know

There are several specific parameters you can include when specifying which process to find:

  • List operations by specifying file size in MB
  • List of operations based on priority
  • Find the owner of the process

6. Get-Service

Your Windows computer has many programs and processes running. While you can view them directly in Task Manager, it's easier to view a complete list using Get-service , which you can convert to HTML Later.

Essential-PowerShell-Commands-Get-Service-800x540.jpg 16 Essential PowerShell Commands You Should Know

Don't remember the exact name of the service you're requesting? You can use the wildcard code. (*) Along with the few letters you can remember.

Get-service "xyz*"

Essential-PowerShell-Commands-Get-Service-Initials.jpg 16 Essential PowerShell Commands You Should Know

Some common signs that work with include: Get-Service -DisplayName و -DependentServices و -InputObject و -RequiredServices.

7. Install-Module or Install-Script

PowerShell is one of the safest options for installing software packages for Windows programs, such as Microsoft Teams McAfee Security, Bing Translator, and the latest Xbox games etc. For a complete list of supported programs in PowerShell for all users, enter:

Get-AppxPackage -AllUsers

Essential-PowerShell-Commands-Get-AppxPackage-800x420.jpg 16 Essential PowerShell Commands You Should Know

The best way is to search for the package you want in PowerShell Gallery, which is a one-stop resource for the latest software packages. Once you find it, enter a command, such as install-module Or Install-Script Or Install-Package. The following explains how to install the game. Minesweeper.

Install-Script -Name Minesweeper

Essential-PowerShell-Commands-Install-Script-800x370.jpg 16 Essential PowerShell Commands You Should Know

Wait a few seconds or minutes for the package to install via PowerShell. It will be available later in Windows.

Essential-PowerShell-Commands-Minesweeper-Package-Installing-800x376.jpg 16 Essential PowerShell Commands You Should Know

Another useful command is Find-package, which searches for a software package on your computer or on the web.

Tip: You can also Use Window Package Manager to install and update software.

8. mkdir, md, rmdir

mkdir is not a native PowerShell command. However, it is a widely used alias for a new command to create directories, as this syntax is very common in DOS and Linux. When you use mkdir with a name of your choice, it creates an empty directory.

mkdir "name of your empty folder."

Make PowerShell point to the newly created folder with a simple cd command.

cd "name of the newly created folder."

Essential-PowerShell-Commands-mkdir-800x440.jpg 16 Essential PowerShell Commands You Should Know

The newly created folder is always located along the path C:\Windows\System32, but you can use CD to point to a different folder.

Also read:  How to check Bluetooth device battery life in Windows 11

Essential-PowerShell-Commands-New-Folder-Created-PowerShell.jpg 16 Essential PowerShell Commands You Should Know

You can replace mkdir with md for the same purpose as above. To remove any directory content, use the rmdir (remove directory) command:

rmdir "name of the folder with empty content."

Essential-PowerShell-Commands-md-rmdir-800x449.jpg 16 Essential PowerShell Commands You Should Know

9. New Item

Unlike aliases like mkdir and md, new item It's the official PowerShell cmdlet used to create new items and set their values. In addition to creating files and folders, you can use it to create registry keys and entries.

  1. To create a new directory using a command new item , Write:
    New-item -Path "Directory location path\" -Name "Name of your choice" -Item Type "directory"
  2. Once you create a directory, you can place new files with a new item inside that folder.
    New-item -path "Created directory location path\" -Name "File name.txt" -ItemType "file" -Value "insert any text of your choice."

    Essential-PowerShell-Commands-New-item-in-use-800x406.jpg 16 Essential PowerShell Commands You Should Know

  3. The newly created file can be found in its destination folder.
    Essential-PowerShell-Commands-New-item-in-File-Explorer-800x552.jpg 16 Essential PowerShell Commands You Should Know

10. Remove-Item

Do you want to remove all files with extensions, such as .TXT, .DOC, .PDF, .WMV, from a folder? First, specify the exact folder path using the CD, and then use the cmdlet remove-item As shown below:

Remove-Item * -Include *(filetype) - Exclude *(any variable or number)"

Essential-PowerShell-Commands-Remove-Item.jpg 16 Essential PowerShell Commands You Should Know

The above method is very useful to identify and remove any hidden, read-only files or delete any files with special characters.

Good to know: Having trouble removing a file from your computer? Find out. How to Force Delete Undeletable Files in Windows.

11. Set-ExecutionPolicy

For security purposes, PowerShell has its own execution policy that affects configuration files, scripts, and other parameters. This security feature can be implemented using the command Set-ecutionPolicy , along with a mark, such as -strength , which overwrites existing elements. The syntax follows.

Set-ExecutionPolicy [-ExecutionPolicy] [[-Scope]] [-Force] [-WhatIf] [-Confirm] []

For example, using the command looks like this: Set-ExecutionPolicy To install Chocolatey, follow the code below. Once executed, the official Chocolatey program will be downloaded and installed on your computer.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

800 Essential PowerShell Commands You Should Know

12. Select-Object and Sort-Object

If your folder or subfolder contains many files and extensions, you may want to sort or select them in ascending or descending order based on a pre-defined property. This is where cmdlets can help. Sort-Object و Select-Object Reorder multiple objects at once.

Sorting and selecting can be applied to any files in different folders, as well as to processes on your computer. Below is an example of sorting and selecting the top ten processes based on their working set (WS) size in megabytes.

Get-process | Sort-Object -Property WS | Select-Object - Last "Number of items"

Essential-PowerShell-Commands-Select-Sort-Objects-800x376.jpg 16 Essential PowerShell Commands You Should Know

You can use sorting and selection on many other parameters, such as historical information of different files, sorting all list items within a Notepad file, and sorting different events on your computer.

13. Start- and Stop-Process

Whether you want to start a new process in Windows or stop an existing one, you can quickly use PowerShell cmdlets to accomplish this goal.

To quickly end a process, use the Stop-Process cmdlet. The following example demonstrates how to close a process in Notebook.

Stop-process -Name "Process or Application name"

Essential-PowerShell-Commands-Stop-Process-WordPad-2.jpg 16 Essential PowerShell Commands You Should Know

Similarly, to start a new application directly from a PowerShell window, enter start process. cmdlet and the sign -F

ilePath.

Start-Process -FilePath "Application name"

Essential-PowerShell-Commands-Start-and-Stop-Processes.jpg 16 Essential PowerShell Commands You Should Know

14. Suspend- and Resume-Service

Instead of starting or stopping a running service, you can suspend it directly. The command Suspend-service The cmdlet is easy to use and helps you reduce RAM and CPU usage for services you are not currently using.

Note: You can use Get-service to get the name of the service to suspend.

Suspend-service -DisplayName "Service full name"

Essential-PowerShell-Commands-Suspend-Service.jpg 16 Essential PowerShell Commands You Should Know

Any terminated service can be resumed later using the command. Resume-service Simple. If you're unsure which services you can suspend without negatively impacting your system, use the following command:

Get-Service | Where-Object {$_.CanPauseAndContinue -eq "True"} | Suspend-Service -Confirm

800 Essential PowerShell Commands You Should Know

15. Test-Path

If you want to avoid making file path errors in programming, you need to ensure that the file path is syntactically accurate. While you can always check using File Explorer, the most accurate way to confirm this is with a command. Test-path cmdlet, which simply answers "True" Or "False" If there is a specific path.

Test-Path -Path "Path name"

Essential-PowerShell-Commands-TestPath.jpg 16 Essential PowerShell Commands You Should Know

You can modify the command to test the availability of a specific file, check if the registry path is accurate, and determine if there are other files besides a specific file type on your computer.

16. Wait-Process

When multiple processes are running side by side, you may want to wait until one or more of them is stopped before you can use them again. This can help. Wait-Process cmdlet. You can specify a timeout period for PowerShell to wait before stopping the process.

Wait-Process -Name "Process name, -Timeout (in seconds)

Essential-PowerShell-Commands-Wait-Process.jpg 16 Essential PowerShell Commands You Should Know

Other basic PowerShell commands

Apart from the PowerShell commands mentioned above, it is also useful to know the following cmdlets and functions:

  • Echo It is a cmdlet used to print any value to the PowerShell console.
  • Give get-host Full details of the program that hosts PowerShell in Windows
  • Test-JSON It is an advanced cmdlet used to test whether a string is a valid JSO object.
  • tracks Trace-command The entire expression or command to find the parameters and flags it contains
  • Write-output , as the name suggests, gives output to the last command in the console window.

Tip: Get up to speed with These Legitimate Windows Processes That Can Look Like Malware To avoid removing it from your system.

Frequently Asked Questions

Q1: How do I resolve the error “PowerShell script not recognized as cmdlet name”?
The answer: If PowerShell doesn't recognize the cmdlet name, it might be because the path variable isn't set correctly. Fix any errors in the path variable by: Correct invalid folder path.

Q2: How can I capture the output of an error as a variable in PowerShell?
The answer: PowerShell has an error variable parameter, $ErrorVariable It is designed to capture all error output when entering various cmdlets. It can be used for troubleshooting.

 

Also read:  Top 5 Ways to Fix Unidentified Network Error on Windows 10
Go to top button