Skip to content

Latest commit

 

History

History
109 lines (67 loc) · 3.72 KB

README.md

File metadata and controls

109 lines (67 loc) · 3.72 KB

PowerShell-Fundamentals

My collection of cheatsheets, code, notes and resources created while learning PowerShell

[[TOC]]

Index

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).

Objects

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

Command Syntax

Verb-Noun – all commands should be formated this way.

Parameters – used to pass info into the command. All prefixed with a “-”.

Positional Parameters

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*

Aliases

Helpful when testing small stuff. Avoid using in your scripts.

Search For A Command to Do Something

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

Loops

While Loops

See PowerShell file titled while-loops.ps1 for examples.

Resources