search
HomeSystem TutorialWindows Series16 Essential PowerShell Commands to Know - Make Tech Easier

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 do almost anything in a PowerShell window. To explain how it works, we list the most basic PowerShell commands.

It is worth mentioning : If Windows cannot find "Powershell.exe", please learn how to retrieve it.

Table of contents

  • How to use PowerShell commands
  • Basic PowerShell Commands
    1. Clear-Host or Cls
    1. Convert-to-HTML
    1. Get-Command
    1. Get-Help
    1. Get-Process
    1. Get-Service
    1. Install-Module or Install-Script
    1. mkdir, md, rmdir
    1. New-Item
    1. Remove-Item
    1. Set-ExecutionPolicy
    1. Select-Object and Sort-Object
    1. Start- and Stop-Process
    1. Suspend- and Resume-Service
    1. Test-Path
    1. Wait-Process
  • Other basic PowerShell commands
  • Frequently Asked Questions

How to use PowerShell commands

To start using cmdlets, you need to start PowerShell in administrator mode from the search menu.

16 Essential PowerShell Commands to Know - Make Tech Easier

Basic PowerShell Commands

PowerShell is not only an active command-line interface in Windows, but also a script and programming window that can run any application or process you want. Although there are hundreds of cmdlets, to get started, you only need to learn the most basic ones.

  1. Clear-Host or Cls

If you make a mistake while typing, or something doesn't go as planned, luckily, you can start over in PowerShell. The convenient clear-host command clears text on the entire screen. Simply enter the command on any line on the screen and everything will disappear immediately.

16 Essential PowerShell Commands to Know - Make Tech Easier

You can also use the simpler cls command commonly used in command prompts to work with PowerShell. These two text-clearing commands are very useful when encountering error messages.

16 Essential PowerShell Commands to Know - Make Tech Easier

To avoid typing errors in the command prompt or PowerShell window, copy and paste the command for efficiency.

Tip : Use PowerShell to hide Windows updates, as shown in this guide.

  1. Convert-to-HTML

Having a bunch of HTML is more beautiful than browsing messy PowerShell screenshots. This is 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 display them in the full browser window, use the Convert-to-HTML cmdlet. Here is an example of viewing all PowerShell alias. Remember to use a separate line before "Invoke-Item".

 <code>Get-Alias | ConvertTo-Html | Out-File aliases.htm<br>Invoke-Item aliases.htm</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Once the HTML conversion command is executed, PowerShell will ask you to open the output file using another application. Use the browser to generate a list of objects, such as alias.

16 Essential PowerShell Commands to Know - Make Tech Easier

  1. Get-Command

There are two main types of commands: alias and functions. The PowerShell alias is the nickname of a function or cmdlet. Windows stores some aliases by default, and you can retrieve them using Get-Command. You can also create your own alias.

16 Essential PowerShell Commands to Know - Make Tech Easier

Another type of command in PowerShell is functions. These use approved verbs (such as “get”) and simple nouns (such as “StorageNode”).

16 Essential PowerShell Commands to Know - Make Tech Easier

We use the "Select-object" function (note the combination of verbs and nouns) with an environment variable called the computer name to display the name of the local computer.

 <code>$env:computername | Select-Object</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Functions are the starting point for advanced PowerShell encoding. You can use functions such as Start-process, to create your own batch script with parameters and variables, performing a series of tasks.

  1. Get-Help

PowerShell has its own self-taught troubleshooting cmdlet, Get-Help, which displays all quick fixes and help articles in one window. Enter a command at the end of any output to get help from various modules. You may need to press the Y key to allow updates to the version of the help content.

16 Essential PowerShell Commands to Know - Make Tech Easier

There are various help options via Get-help. For example, if you want to know what Get-process does and its exact syntax, enter the following:

 <code>Get-Help Get-Process</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Tip : Worrying about the keyboard recorder monitoring your activity on your PC? Learn how to detect a keyboard logger on Windows.

  1. Get-Process

Get-Process is a basic PowerShell command that lists all processes on a local device or remote computer.

16 Essential PowerShell Commands to Know - Make Tech Easier

To obtain more detailed process information, you need to specify additional parameters such as process ID (PID) or process name.

16 Essential PowerShell Commands to Know - Make Tech Easier

When defining the process you are looking for, you can include many specific parameters:

  • List process file sizes by MB
  • List processes by priority
  • Find the owner of the process
  1. Get-Service

There are many running programs and processes on your Windows computer. While you can view them directly in Task Manager, it will be easier to view the full list with Get-service, which you can convert to HTML later.

16 Essential PowerShell Commands to Know - Make Tech Easier

Don't remember the exact name of the service you need? You can use wildcard symbols (*) and a few letters you can recall.

 <code>Get-service "xyz*"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Common flags used with Get-Service include -DisplayName, -DependentServices, -InputObject, and -RequiredServices.

  1. Install-Module or Install-Script

PowerShell is one of the most secure options for installing packages for Windows software such as Microsoft Teams, McAfee Security, Bing Translator, the latest Xbox games, and more. To get a complete list of all user-supported software in PowerShell, enter:

 <code>Get-AppxPackage -AllUsers</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

A better approach is to search for required packages in PowerShell Gallery, a one-stop resource for the latest packages. Once it is found, enter a command such as Install-module, Install-Script, or Install-Package. The following shows the command to install the minesweeping game.

 <code>Install-Script -Name Minesweeper</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Wait for a few seconds or minutes to allow the package to be installed through PowerShell. It will be available in Windows later.

16 Essential PowerShell Commands to Know - Make Tech Easier

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

Tip : You can also use Windows Package Manager to install and update programs.

  1. mkdir, md, rmdir

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

 <code>mkdir "您选择的空文件夹名称"</code>

Use a simple cd command to let PowerShell point to your newly created folder.

 <code>cd "新创建的文件夹名称"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

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

16 Essential PowerShell Commands to Know - Make Tech Easier

You can replace mkdir with md for the same purpose. To delete any directory contents, use the rmdir (delete directory) command:

 <code>rmdir "内容为空的文件夹名称"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

  1. New-Item

Unlike aliases such as mkdir and md, New-item is the official cmdlet in PowerShell for creating new projects and setting their values. In addition to creating files and folders, you can also use it to create registry keys and entries.

  1. To create a new directory using the New-item command, enter:
 <code>New-item -Path "目录路径位置\" -Name "您选择的名称" -ItemType "directory"</code>
  1. Once the directory has been created, you can place new files in that folder using New-item.
 <code>New-item -path "已创建的目录路径位置\" -Name "文件名.txt" -ItemType "file" -Value "插入您选择的任何文本"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

  1. The newly created file can be found in its target folder.

16 Essential PowerShell Commands to Know - Make Tech Easier

  1. Remove-Item

Do you want to delete all files with extensions from the folder, such as .TXT, .DOC, .PDF, .WMV? First, use cd to point to the exact folder path, and then use the Remove-Item cmdlet as shown below:

 <code>Remove-Item * -Include *(文件类型) -Exclude *(任何变量或数字)"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

The above method is very useful for identifying and deleting any hidden or read-only files or for deleting files with special characters.

It's worth mentioning : If you can't delete files from your PC, learn how to force delete files that cannot be deleted in Windows.

  1. Set-ExecutionPolicy

For security purposes, PowerShell has its own execution policy that affects configuration files, scripts, and other parameters. This security feature can be executed using the Set-executionPolicy command and overwrites existing projects with the -force flag. The syntax is as follows.

 <code>Set-ExecutionPolicy<br>[-ExecutionPolicy]<br>[[-Scope] ]<br>[-Force]<br>[-WhatIf]<br>[-Confirm]<br>[]</code>

For example, the code for installing Chocolatey software using the Set-ExecutionPolicy command is as follows. Once executed, it will download and install the official Chocolatey software on your computer.

 <code>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'))</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

  1. Select-Object and Sort-Object

If you have many files and extensions in your folder or subfolder, you may want to sort or select them in ascending or descending order based on predefined properties. This is where Sort-Object and Select-Object cmdlets can help you rearrange multiple objects at once.

Sort and selection can be applied to any file in different folders as well as existing processes on your computer. Here is an example of sorting and selecting the ten most important processes in megabytes based on the working set (WS) size.

 <code>Get-process | Sort-Object -Property WS | Select-Object -Last "项目数量"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

You can use sorting and selection for various other parameters, such as history information for various files, sorting all list items contained in Notepad files, and sorting various events on your computer.

  1. Start- and Stop-Process

Whether you want to start a new process in Windows or stop an existing process, you can quickly use the PowerShell cmdlet to achieve this.

To kill a process quickly, use the Stop-Process cmdlet. The following example shows how to close the process of WordPad.

 <code>Stop-process -Name "进程或应用程序名称"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Similarly, to start a new application directly from the PowerShell window, enter the Start-process cmdlet and -FilePath flags.

 <code>Start-Process -FilePath "应用程序名称"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Tip : Learn how to stop background applications and processes running in Windows to avoid them consuming your resources.

  1. Suspend- and Resume-Service

Instead of starting or stopping it, you can pause a running service directly. The Suspend-service cmdlet is simple to use, helping you reduce the RAM and CPU usage of services you are not currently using.

Note : You can use Get-service to get the name of the service you want to pause.

 <code>Suspend-service -DisplayName "服务全名"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Any terminated service can be restored later using the simple Resume-service command. If you are not sure which services can be paused without negatively affecting the system, use the following command:

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

16 Essential PowerShell Commands to Know - Make Tech Easier

  1. Test-Path

If you want to avoid making file path errors in programming, you need to make sure that the file paths in the syntax are accurate. While you can always use File Explorer for verification, it is more accurate to confirm this with the Test-path cmdlet, which will only answer "True" or "False" to indicate whether the given path exists.

 <code>Test-Path -Path "路径名称"</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

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

  1. Wait-Process

When multiple processes are running at the same time, you may want to wait for one or more of the processes to stop before using them. Wait-Process cmdlet can help you a lot. You can specify the timeout for PowerShell to wait for before the process stops.

 <code>Wait-Process -Name "进程名称" -Timeout (以秒为单位)</code>

16 Essential PowerShell Commands to Know - Make Tech Easier

Other basic PowerShell commands

In addition to the PowerShell commands listed above, it is also helpful to learn the following cmdlets and functions:

  • Echo is a cmdlet for printing any value on the PowerShell console
  • Get-Host provides complete details about PowerShell hosting programs in Windows
  • Test-JSON is a high-level cmdlet used to test whether a string is a valid JSO object
  • Trace-command tracks the entire expression or command to find the parameters and flags contained in it
  • Write-output, as its name, outputs the output of the last command in the console window.

Tip : Quickly learn about these legitimate Windows processes that look like malware to avoid removing them from the system.

Frequently Asked Questions

How to fix the error "PowerShell script not recognized as cmdlet name"?

If PowerShell fails to recognize the cmdlet's name, it may be because the path variable is not set correctly. Fix any path variable errors by correcting its invalid folder path.

How to capture error output as a variable in PowerShell?

PowerShell has an error variable parameter, $ErrorVariable, designed to capture all error output when you enter various cmdlets. These can be used for troubleshooting.

Image source: DepositPhotos. All screenshots were taken by Sayak Boral .

The above is the detailed content of 16 Essential PowerShell Commands to Know - Make Tech Easier. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Automate Repetitive Tasks via AI-Generated PowerShell Scripts - Make Tech EasierAutomate Repetitive Tasks via AI-Generated PowerShell Scripts - Make Tech EasierMay 16, 2025 am 02:35 AM

I've always held the belief that computers should serve us, rather than the reverse. This belief was tested when I found myself dedicating endless hours to repetitive tasks. However, this changed when I began leveraging artificial intelligence (AI) t

What To Do if There's an Unusual Sign in Activity on Your Microsoft AccountWhat To Do if There's an Unusual Sign in Activity on Your Microsoft AccountMay 16, 2025 am 02:34 AM

Similar to other large companies, Microsoft prioritizes your account security and protection from unauthorized access by individuals with harmful intentions.If Microsoft detects an unusual login attempt, it marks it as suspicious. You will receive an

How to Roll Back a Driver in Windows - Make Tech EasierHow to Roll Back a Driver in Windows - Make Tech EasierMay 16, 2025 am 02:33 AM

Driver issues are quite common in Windows systems. Sometimes, updates to new drivers may cause a Blue Screen of Death (BSOD) error message in Windows. Fortunately, this problem can be solved by rolling back the driver. You can use the Rollback Driver feature to restore the driver update to a previous version to check if it is functioning properly. Here is a detailed guide on how to roll back drivers in Windows. Directory Rollback Driver in Windows What to do if the Rollback Driver option is disabled? FAQ Rollback Driver in Windows Windows comes with some built-in tools designed to detect and resolve possible conflicts in the operating system. This pack

How to Take Full Ownership of Windows Registry Keys - Make Tech EasierHow to Take Full Ownership of Windows Registry Keys - Make Tech EasierMay 16, 2025 am 02:28 AM

The Windows Registry is a central hub for storing all configurations related to the Windows operating system and its software. This is why numerous Windows tutorials often involve adding, modifying, or deleting Registry keys.However, you may encounte

How to Remove 'System Requirements Not Met” Watermark in Windows 11 - Make Tech EasierHow to Remove 'System Requirements Not Met” Watermark in Windows 11 - Make Tech EasierMay 16, 2025 am 02:27 AM

Windows 11 does have strict installation requirements. However, installing Windows 11 on unsupported devices is not difficult. If you have successfully installed it, don't rush to celebrate. You also need to clear the desktop "System Requirements Not Meeted" watermark that Microsoft introduced to prevent installation on unsupported hardware. This guide lists three ways to remove this watermark. Directory Group Policy Editor Windows Registry Editor Script Group Policy Editor If you are using Windows Pro or Enterprise and you have Group Policy Editor enabled, this method is the easiest. Follow the instructions below to disable the watermark through the Group Policy Editor. Enter "Group Policy" in Windows Search and click Edit Group in the results

Microsoft Teams Camera Not Working? Learn How to Fix ItMicrosoft Teams Camera Not Working? Learn How to Fix ItMay 16, 2025 am 02:22 AM

Microsoft Teams is a widely used platform for collaboration and communication within organizations. Despite its effectiveness, you might occasionally face issues with the camera during calls. This guide offers a range of solutions to resolve the came

How to Check Your RAM Type in Windows - Make Tech EasierHow to Check Your RAM Type in Windows - Make Tech EasierMay 16, 2025 am 02:21 AM

If you plan to upgrade your RAM or test its performance, it is important to know your RAM type. This means that your laptop or PC needs to be evaluated to determine the DDR module it supports, as well as other details like the form, speed and capacity of RAM. This tutorial shows how to check RAM types using various Windows applications and third-party tools in Windows. Directory Check RAM type via command prompt Check RAM type via task manager Check RAM type in Windows Check RAM type in PowerShell Check RAM type using CPU-Z Check RAM type using Novabench Check RAM type via visual inspection of motherboard Check RAM type via command prompt Check RAM type

How to Fix 'Local Security Authority Protection Is Off' on Windows - Make Tech EasierHow to Fix 'Local Security Authority Protection Is Off' on Windows - Make Tech EasierMay 16, 2025 am 02:20 AM

Local Security Authority (LSA) protection is a crucial security feature designed to safeguard a user's credentials on a Windows computer, preventing unauthorized access. Some users have encountered an error message stating that "Local Security A

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools