Resources
- Getting Started with Windows PowerShell from Microsoft
- PowerShell Documentation from Microsoft
- Sample PowerShell Scripts from Microsoft
- PowerShell Community Blog from Microsoft
- Hey, Scripting Guy! Blog from Microsoft (older content)
Video Script
Before digging too deep into Windows, let’s take some time to learn about one of its most powerful, and least used, features, the PowerShell command line interface. PowerShell is an update to the old Command Prompt terminal, which was a very limited version of the DOS terminal from decades ago.
PowerShell is built on top of the .NET framework, and can leverage many features of that programming environment to perform powerful tasks within a simple interface. While we won’t go too deep into PowerShell in this class, it is a very useful thing to learn.
On your Windows 10 Virtual Machine, you can open PowerShell by searching for it on the Start Menu.
The PowerShell interface is very simple, with just a small terminal that you can use to enter commands. Most commands take the form of a verb, followed by a hyphen, and then a noun. Let’s try a few to see how they work:
Get-Location
- get the current directorySet-Location <path>
- change directoryGet-ChildItem
- list filesNew-Item <name> (-ItemType <"file" | "directory"> -Value <value>)
- make a new directory or fileGet-Content <name>
- get file contentsRemove-Item <name>
- remove a directory or fileCopy-Item <name>
- copy a directory or fileMove-Item <name>
- move a directory or fileSelect-String -Pattern <pattern> -Path <path>
- search for a string in a file or group of filesGet-Command
- get a list of commandsGet-Help
- get help for a commandGet-Alias
- get a list of aliases for a commandOut-File
- output to a file
If you want to use the output of one command as input to another command, you can use the vertical pipe character |
between commands. Here are some examples.
Select-String
- search for a string in outputMeasure-Object <-Line | -Character | -Word>
- get line, word or character countSort-Object
- sort output by a propertyWhere-Object
- filter output by a property
You can also use PowerShell to write and execute scripts of commands. It is very similar to writing code in a programming language, but it is outside of the scope of this class. If you are interested in learning more, there are many great resources linked below the video to get you started. You can also check out the crash-course on PowerShell scripting in the Extras module.