PowerShell Frequently Asked Questions

A collection of questions (and answers), curated by the PowerShell Virtual User Group on Discord and Slack.

Is there any free training for PowerShell

Most PowerShell content from Microsoft is in the form of product-specific training. As far as the language itself, there's rarely more than the introduction to PowerShell on Microsoft Learn. You should also check out PS Koans. There are a lot of videos, books, and commercial classes, but that's a different question.

What books do you recommend for newbies?

For beginners, there's general agreement that one of the best ways to get started is Don Jones's Learn Windows PowerShell in a Month of Lunches, which is currently in it's third edition. It's published by Manning, and there are a couple of free chapters on their website.

What books can help me learn to write PowerShell modules?

If you would like to go deeper, and prefer to learn by reading and doing, the Learn PowerShell Toolmaking in a Month of Lunches book by Don Jones and Jeffrey Hicks is a great place to start. It's published by Manning, so there are a couple of free chapters on their website.

What books do you recommend for programmers?

The most comprehensive book about PowerShell is still, without a doubt, Windows PowerShell in Action by Bruce Payette (one of the original language architects). The Third Edition is available now, with updates by Richard Siddaway. It's published by Manning, so there are a couple of free chapters on their site.

What books do you recommend for .NET developers?

If you're a .Net developer that's trying to learn PowerShell, you might also have a look at Windows PowerShell for Developers, by Douglas Finke -- it's full of scripts that you can relate to, and that will help you learn to embed PowerShell in your apps for scripting, automate task in development, and interact with .Net and native DLLs, COM, etc.

Are there any free PowerShell ebooks?

There are a lot of free eBooks available. A great list of PowerShell books (which includes some free ones) was compiled a few years ago by Jason Hofferle. It includes many from PowerShell.org, and there are more published under the "Devops Collective" on GitBook. Our favorites are Why PowerShell? and The Big Book of PowerShell Gotchas.

Are there free video classes?

There are several days worth of free PowerShell classes available via Channel 9, in fact, the first two courses we used to recommend for anyone would be the full-day length "Getting Started with Microsoft PowerShell" and "Advanced Tools & Scripting with PowerShell 3.0 Jump Start" which are both presented by Microsoft Technical Fellow and inventor of PowerShell Jeffrey Snover, working with Jason Helmick.

Are there any videos about PowerShell DSC?

Of course! Microsoft Technical Fellow and so-called ShellFather Jeffrey Snover, and current PowerShell PM Jason Helmick put together "Getting Started" and "Advanced" courses for PowerShell DSC (Desired State Configuration), which reach run about a whole day.

Is there any free video training for PowerShell 5?

There's a lot. Channel 9 has a series of PowerShell 5 videos from 2016 by MVP Trevor Sullivan which are pretty short and basic on their PowerShell show. That same year, the PowerShell Team put together almost a whole day of content to celebrate the 10 year anniversary of PowerShell in production.

There are many other videos available on MVA of course, and on Channel 9 -- including the recent 10th Anniversary event, and Jeffrey Snover and Don Jones' annual "PowerShell Unplugged" presentations at Ignite, and an awful lot of content on Pluralsight...

Where are all the PowerShell Unplugged videos?

Here are all the PowerShell Unplugged videos we could find, starting in: 2014, 2015, 2016, 2017, 2018 I can't find, and 2019 I only found on YouTube and Pluralsight, 2020 was different, of course -- and 2021 isn't available (yet).

Why should I learn PowerShell?

PowerShell is a cross-platform shell and scripting language that's required for managing Windows servers, and is capable of managing the cloud, including Linux and Windows, Azure, AWS and GCP. If you want to automate something, PowerShell is both a task-based command-line shell, and a powerful scripting language -- with full access to the .Net Framework. It's also the standard for managing Windows Server and other Microsoft server products and services.

If you need more, Warren Frame and Don Jones wrote a short eBook on the subject. Why PowerShell?

How do I fix "the execution of scripts is disabled on this system" errors?

On Windows desktops and older versions of Windows Server, not only is the .ps1 extension not associated with PowerShell, PowerShell scripts are not enabled by default. In order to run scripts, you must first run Set-ExecutionPolicy RemoteSigned. If you're not the administrator of the machine, you may need to add the -Scope CurrentUser option. For more information, read the help: Get-Help Set-ExecutionPolicy -Online.

An administrator may alter the execution policy for a single instance PowerShell when launching PowerShell by using the ExecutionPolicy parameter (ie: PowerShell.exe -ExecutionPolicy Bypass).

How do I set the PATH in PowerShell?

The PATH, like all environment variables, is accessible in PowerShell via the Env drive, and you can set it using variable syntax, like: $Env:PATH += ";$pwd" to add the present working directory to it. In Windows, the directory separator for the path is ";", but on Linux it's ":" -- to be safe, you can use [IO.Path]::PathSeparator like this: $Env:Path += [IO.Path]::PathSeparator + $pwd

Note that += is the "append" operator for strings.

To make changes permanent you can either put them in a profile script (which is cross-platform), or if you need the changes to affect apps outside PowerShell on Windows, you can force them into the environment storage using [Environment]::SetEnvironmentVariable -- but you must be careful, in this case, not to put your personal environment into the machine's environment. Here's a simple two-line script that will add a path to the PATH environment variable for all users in Windows:

function Add-Path($Path) {
    $Path = [Environment]::GetEnvironmentVariable("PATH", "Machine") + [IO.Path]::PathSeparator + $Path
    [Environment]::SetEnvironmentVariable( "Path", $Path, "Machine" )
}

How do I pass parameters to PowerShell scripts?

Passing arguments in PowerShell is the same as in any other shell: you just type the command name, and then each argument, separated by spaces. If you need to specify the parameter name, you prefix it with a dash like -Name and then after a space (or a colon), the value. If the parameter is a "switch" then specifying it's name sets it to True, so you should not provide a value. Passing multiple values to the same parameter requires commas (and optionally, the @(...) array specifier).

Accepting parameters in a PowerShell script (or function) is done by adding a param block at the top with a comma-separated list of parameter names:

function Test-Script {
    param($Name,$Age)
    "$Name is roughly $Age years old"
}

Test-Script "The Doctor" "4.5 billion"
Test-Script -Name Mother -Age 29

How do I determine the location of the current PowerShell script?

Ever since PowerShell 3, there is an automatic variable $PSScriptRoot which is set to the path of the directory that contains the currently-executing module or script. Additionally, there is $PSCommandPath which contains the path (including the file name) to the currently executing script.

How do I determine the current version of PowerShell?

The version of PowerShell is always available within PowerShell in the $PSVersionTable as the "PSVersion" property. As of PowerShell 5, there is also a "PSEdition" property (which is also available as it's own $PSEdition variable) to distinguish Windows PowerShell (the "Desktop" edition) from PowerShell Core (the "Core" edition).

What's the license for this FAQ?

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

You are free to:

Share — copy and redistribute the material in any medium or format

Adapt — remix, transform, and build upon the material

Under the following terms:

Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

For more details, or to view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

The authors encourage you to redistribute this content as widely as possible, but request that you link to the PowerShell FAQ project or the gitbook url for the original source.

How can I contribute to the FAQ?

This FAQ is a GitHub project: PoshCode/PowerShellFAQ. Please note all contributions are under the cc-by-sa license.

How do I add a new question and answer?

Make a pull request to PoshCode/PowerShellFAQ, adding a file in one of the sub-folders of "src" with your question and it's answer.

Note that for the "book" version on PoshCode.org/PowerShellFAQ you must add the question as a link in the SUMMARY.md.

Can I add a question without an answer?

To add a question without an answer, use the GitHub issues. We can't guarantee that all of these will be added, because sometimes answers are just too complicated for our format...

What makes a good FAQ entry?

Any frequently asked question that can be summarized in a single sentence, and answered in one or two paragraphs. Because of limitations on some of the clients that these questions are asked on, we need each paragraph to be under 450 characters in length. If you must, you can provide multiple paragraphs, or hyperlinks to additional content.

Can I just suggest an improvement to the answer for a question?

You can! Feel free to submit a pull request to PoshCode/PowerShellFAQ with better answers, or to just open an issue and we'll take care of it. We welcome your contributions, whether it's new questions, corrections, updates, or suggestions for better answers!