温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.muo.com/windows-powershell-scripting/
点击访问原文链接

What Is Windows PowerShell Scripting?

What Is Windows PowerShell Scripting? Menu Sign in now Close PC & Mobile Submenu Windows2 Linux Android Apple Technical Submenu Tech Explained Security Software Submenu Productivity Internet Creative Screen Submenu Entertainment Streaming Home Submenu Smart Home Home News Sign in Newsletter Menu Follow Followed Like More Action Sign in now Productivity Android Smart TVs Networking Windows 11 Entertainment Close
What Is Windows PowerShell Scripting? Image by Jayric Maning --No attributions required By  Jayric Maning Published Jan 19, 2024, 11:00 AM EST

Jayric is a Forensic Science graduate with over five years of writing experience and a passion for reverse engineering and hardware.

 

His tech journey kicked off in childhood with an old hand-me-down Nokia N91, where he repackaged Java games like a Symbian port of Pokémon Blue to tweak TMs and Poké Dollars. By high school, he was flashing custom Android ROMs and trading modded games for lunch money, and in college, he learned C/C++ and electronics on a TI Tiva C LaunchPad, then went on to create DIY projects ranging from USB security keys to home automation devices.

 

Jayric now enjoys writing at MUO to keep sharing and learning about tech while honing his own craft. Outside of tech, he enjoys grinding CS2 and Dragon Nest, lifting weights, running daily 5Ks, and reading in his greenhouse.

Sign in to your MakeUseOf account Summary PowerShell is a scripting language that can help automate computer tasks. Cmdlets are single-function Powershell commands. You can view available commands with "Get-Command." PowerShell is available on Windows, macOS, and Linux.

PowerShell is a scripting language that can help you automate computer tasks simply and reliably. Find out how to use it to start building scripts for your Windows PC.

PowerShell Scripting Overview

To start making simple PowerShell scripts on Windows, you'll need to know about three things:

Cmdlets: single function commands. Parameters: specify the what, when, where, and how of Cmdlets/commands. Pipeline: takes the output of your Cmdlet and its parameters and connects it to other Cmdlets and functions.

Combining all three, you can make simple scripts to help automate tasks.

Here's an example pipeline showing how you can combine several Cmdlets to achieve a task:

Illustration by Jayric Maning --No attributions required

To run this pipeline in PowerShell, you would use something like this command:

Get-Object Potato | Peel-Object | Chop-Object Chips| Cook-Object DeepFry `
| Place-Object Bowl
Cmdlets in Detail

Like any scripting language, PowerShell comes pre-built with commands to manipulate objects and perform various tasks. These fundamental commands within PowerShell are known as Cmdlets.

Cmdlets (pronounced as command-lets) are small, single-function commands used in the PowerShell environment using the .dll extension. They are lightweight pieces of code that execute quicker than functions due to their compiled nature.

There are thousands of Cmdlets available on PowerShell. You do not need to learn all of them. You can start by learning a few basic PowerShell Cmdlets then keep learning as you go through your scripting journey. To view the Cmdlets that are already installed on your computer, run:

Get-Command

If you scan through the results, you’ll notice that they follow a verb-noun naming convention. This makes it easier to understand what a certain Cmdlet does.

For example, Get-Command gives a list of commands available in PowerShell. Get-Process gets you the processes that are currently active, and Copy-Item copies one or more files to a specific directory.

Cmdlets also come bundled with extensive documentation that includes examples, usage instructions, and explanations of their functionality.

To find out more about a specific Cmdlet and how to use it, run:

Get-Help 
PowerShell Parameters Explained

Cmdlets can accept parameters to vary their behavior. When you run a Cmdlet or function, you can provide parameter values to specify what, when, where, and how each PowerShell command runs.

For example, Get-Process will get and list of all the active processes within your operating system:

Screenshot by Jayric Maning --No attributions required

But what if you only want to get a specific process? You can do so using parameters. For example, to get all Slack processes, you can use the Name parameter with the Get-Process Cmdlet:

Get-Process -Name Slack

You will then see only those processes with the name "slack":

Screenshot by Jayric Maning --No attributions required

Some parameters are "positional" which means their name is optional. In this case, Get-Process -Name Slack and Get-Process Slack do the same thing.

Each Cmdlet will accept different types of parameters. Use the Get-Help command to view the accepted parameters of a Cmdlet in the SYNTAX section.

Get-Help Get-Process

You’ll see a list of all possible ways you can run the given Cmdlet:

Screenshot by Jayric Maning --No attributions required

In this case, the Get-Process Cmdlet accepts parameters such as Name, Id, ComputerName, Module, FileVersionInfo, and other common parameters. The symbols here signify:

Symbol

Name

Meaning

Blank

Parameter doesn’t accept input

-

Hyphen

Indicates parameter name

<>

Angled Brackets

Placeholder for text

[]

Brackets

Parameter that can accept one or more values

{}

Braces

Parameter accepts a set of values

Parameters that accept inputs will indicate the type of data they require, such as a string, integer, boolean, or DateTime. For example, this:

Get-Process [[-Name] ]

Means that the Name parameter accepts one or more string values, while this:

Get-Process -Id 

Means that the Id parameter accepts one or more integer values.

The earlier Get-Process example used the Name parameter to narrow down the results. However, if you want to narrow it down to an even more specific process, you can use the ID parameter, which requires an integer as stated in its syntax.

Get-Process -Id 3016

You should then see just one process in the list:

Screenshot by Jayric Maning --No attributions required Creating a Pipeline

PowerShell treats all data as objects. To build a script, these objects flow through a series of Cmdlets or functions connected by a pipe symbol ( | ). Choosing the right Cmdlets and connecting them in a logical sequence using the pipeline is crucial for an effective script.

Say you’re creating a script to sort and display the five files taking the most storage space in a folder. There are more robust ways of creating a file-sorting script, but the following one-liner is easy to understand:

Screenshot by Jayric Maning --No attributions required

To do this in PowerShell, use a pipeline that looks something like this:

Get-ChildItem -Path "C:\Directory" -File | Sort-Object Length -Descending `
| Select-Object -First 5 | Format-Table Name, Length -AutoSize
Saving Pipeline as a PS1 Script

Now that we have a working pipeline, you can save it as a PS1 script file, so you don't have to keep typing it every time you use it.

The simplest way to create a PS1 file is to paste your script into Notepad and save the file with the .ps1 extension.

Screenshot by Jayric Maning --No attributions required

Once you've created your PS1 file, you can use it in PowerShell by running ./ScriptName.ps1:

Screenshot by Jayric Maning --No attributions required

If you get a permission error, the quickest workaround is to run PowerShell as administrator when running your scripts.

Congratulations! You can now create PowerShell PS1 scripts.

PowerShell Is Also Available on Linux and macOS

PowerShell is one of the best beginner scripting languages anyone can learn. Although PowerShell was only limited to Windows in the past, the updated version of PowerShell is now also available on macOS and many Linux distributions! This makes PowerShell even more appealing as you can transfer your knowledge from Windows to other operating systems.

Close
Recommended What to Do When Windows Cannot Find PowerShell I disabled one Windows background service and my PC stopped freezing mid-task The fastest photo editor on my Windows PC doesn't need installing Most streaming sticks have terrible remotes — this is what a good one feels like Join Our Team Our Audience About Us Press & Events Media Coverage Contact Us Follow Us Advertising Careers Terms Privacy Policies MakeUseOf is part of the Valnet Publishing Group Copyright © 2026 Valnet Inc.

What Is Windows PowerShell Scripting?,AI智能索引,全网链接索引,智能导航,网页索引

    Looking to automate tasks on your PC? Try PowerShell scripting!