My collection of cheatsheets, code, notes and resources created while learning PowerShell
[[TOC]]
- Accessing Data from Computer Hardware
- Arrays
- ArrayObjects
- Command Syntax
- Iterate Over CSV Files
- Objects
- Positional Parameters
- PowerShell for AWS
- Quick Command Reference
- Read Files
- Search For A Command to Do Something
- Types of PowerShell
Powershell core – newer. Does not come with Windows by default. Can do nearly all the same stuff. Allows us to run commands on multiple platforms, unlike Powershell. Based on .netcore. Downloadable from GitHub. Can be run on Windows, Linux and MacOS. The future way of working with PS. An open source project. Only has a subset of Windows PS commands, but it’s a large subset. To open in computer, can type “pwsh"
Windows Powershell ISE – integrated scripting engine. The original built in editor for editing PS scripts. Comes installed by default.
Windows Powershell - most popular. Built into Windows. Only on windows; can’t install or run on mac or linux. Based on the .net standard, using the .net framework that PS is built on. Development has stopped for Windows Powershell (no further updates, except for security stuff).
PowerShell treats all data as objects.
Can be both text based and objects based.
PS commands use objects as their output, which is helpful, since objects properties and methods.
Used with pipes, the object that is outputted from one command is passed to the next command.
Get-Service|Select-Object name,starttype,servicetype|more
Verb-Noun – all commands should be formated this way.
Parameters – used to pass info into the command. All prefixed with a “-”.
It expects in the first position that the "name" parameter will appear. This means that you can shorten commands for named parameters.
Instead of:
get-service -name p*
You can simply write:
get-service p*
Or, if you're also using Aliases:
gsv p*
Helpful when testing small stuff. Avoid using in your scripts.
Example: Say, you're looking for runtime dynamic data, particularly a runtime performance counter.
Do a general search for commands that have the word counter in them, with wildcards around the word to indicate that the word can be at the beginning, middle or end of a command.
get-command *counter*
check help for the one that looks promising.
help get-counter
Look at the Syntax section for flags to use.
Try the main command
MORE CONTENT PENDING
See PowerShell file titled while-loops.ps1 for examples.
- Udemy course – "Windows PowerShell in less than 2 hours – 15 hands on demos," taken in October 2020.
- The Big Book of PowerShell Gotchas
- PowerShell and while loops