Understanding the Powershell Platform Flashcards
Name the two Powershell “flavors”
The “Command Window” and ISE
Name the two Powershell “flavors”
The “Command Window” and ISE
What are the methods to retrieve a directory listing?
dir
ls
Get-ChildItem
The best way to customize the command window or ISE is via the…
Shortcut to the relevant program. This means that the changes will be remembered.
Command Window is useful for
Calling Scripts
Exploratory Work
ISE is useful for
Development
Powershell scripts have the extension
.ps1
Single line comments begin with a
#
Multiline comments begin and end with
Regions are denoted with
#region [Optional Title] #endregion [Optional Title]
How do you retrieve a list of all system cmdlets?
Get-Command
How do you retrieve a list of all system commands?
Get-Command
How do you retrieve a list of only cmdlets that have a noun of “Service”
Get-Command -noun “Service”
How do you get help for a given cmdlet
Get-Help [Cmdlet Name]
e.g. Get-Help Get-Command
Command Window is useful for
Calling Scripts
Exploratory Work
How do you see the online version of a help entry?
Get-Help [Command-Name] -online
What’s the shortcut for pulling up help?
Command-Name -?
Single line comments begin with a
#
Multiline comments begin and end with
How do we find which command a specific alias points to?
Get-Alias [alias]
All commandlets (cmdlet) are structured as
Verb-Noun
How do you retrieve a list of all system cmdlets?
Get-Command
How do you retrieve a list of only cmdlets that have a verb of “Get-“
Get-Command -verb “Get”
How do we set the current directory?
Set-Location “path\or\relative\path”
How do you get help for a given cmdlet
Get-Help [Cmdlet Name]
e.g. Get-Help Get-Command
What is the typical structure of a Help entry?
NAME SYNOPSIS SYNTAX DESCRIPTION RELATED LINKS REMARKS
How do you see the online version of a help entry?
Get-Help [Command-Name] -online
When working with a collection (in a pipelining scenario), how do you specify the “current” object?
$_
What is the syntax for specifying all files with a length greater than 10kb?
Get-ChildItem | Where-Object{$_.Length -gt 10kb}
How do we find out all Aliases on that have been imported?
Get-Alias
How do we find which command a specific alias points to?
Get-Alias [alias]
How do we find which aliases exist for a given cmdlet?
Get-Alias -Definition [cmdlet-Name]
Is it wise to use aliases in prod code?
No - people don’t necessarily know the aliases so best to use the full cmdlet name.
What is pipelining?
A method in PowerShell by which we can chain cmdlets together.
How do we set the current directory?
Set-Location “path\or\relative\path”
What is the character that is used for pipelining?
The pipe “|”
What is the filtering cmdlet for pipelining?
Where-Command
In PowerShell, everything that you work with is an..
object
When working with a collection (in a pipelining scenario), how do you specify the “current” object?
$_
What is the syntax for specifying all files with a length greater than 10kb?
Get-ChildItem | Where-Object{$_.Length -gt 10kb}
Back in Help, conceptual topics start with…
about_
How do we get a list of conceptual topics
Get-Help about_*
Which cmdlet do you use to sort a collection?
Sort-Object
What is the syntax to retrieve a list of files whose length is greater than 10kb, sorted by length?
Get-ChildItem | Where-Object{$_.Length -gt 10kb} | Sort-Object Length
How do you get details about the current version of PowerShell that is installed?
$PSVersionTable
When pipelining how can you split the source code lines?
Make sure that the pipe character is the VERY LAST character on the line before starting a new line.
Given the following:
Get-ChildItem |
Where-Object {$_.Length -gt 10kb} |
Sort-Object Length
How could you specify which properties to return?
Use Format-Table -Property [PropName1], [PropName2] etc
-AutoSize to automatically pad where necessary.
Given Get-ChildItem how can we extract certain properties into a new object?
Get-ChildItem | Select-Object Name, Length
for example
If we’re not using pipes, how can we split commands up over multiple lines?
Back-tick (`)
It HAS to be the last character (like the pipe)
Get-ChildItem returns items from a ….
Provider
How do you get the list of providers that are available?
Get-PSProvider
How can a specific provider be specified when using Get-ChildItem
Specify the “drive” in the path. Eg:
Get-ChildItem env:
returns environment variables.
Using pipelining, how can we pipe results into a gui Grid View?
Out-GridView
e.g. Get-ChildItem | Out-GridView
Use -PassThrough switch to ensure that data is passed from the grid view through to the next cmdlet.
With the GridView how do we restrict / enable multiple selections?
- OutputMode Single or
- OutputMode Multiple
How can I specify a Title for the Grid View?
-Title “Title to display”
How can I pass the selections from a GridView into a variable?
Use the -OutVariable parameter.
E.g.:
$ov = $null
Get-ChildItem | Out-GridView -PassThru -OutVariable $ov
How do I clear the output screen
Clear-Host
How do I get a list of drives (be they physical or provider-based)?
Get-PSDrive
How can I set my own PS Drive?
Use Set-PSDrive e.g. New-PSDrive -Name cw ` -PSProvider FileSystem ` -Root C:\Users\chrisw
How can I remove that PSDrive?
Remove-PSDrive [PSDriveName]