Skip to content

Instantly share code, notes, and snippets.

@cubanx
Forked from rgborck/Powershell Class Outline
Created September 26, 2016 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cubanx/8a6d37faac5e448122badb29bf2fde80 to your computer and use it in GitHub Desktop.
Save cubanx/8a6d37faac5e448122badb29bf2fde80 to your computer and use it in GitHub Desktop.
This is an outline of a PowerShell class I taught to my coworkers in the fall of 2015
Powershell - Lesson 1
Configuration:
Powershell profile
Import-Module Grc
(Test it w/ `Get-GrcTenants`)
Syntax:
Variable declaration $
Powershell variables ( $true, $null, $false, etc )
Control Structures
Conditionals (-eq, -ne, -contains, etc)
Calling functions and commandlets (For
Arrays @()
Dictionary @{}
Variable Persistance - `Get-Variable | Out-String`
| operator
> Get-GrcTenants |% {Write-Host $_.Name}
Write-Host including writing variables in strings and piping variables into ConvertTo-Json and writing the result embedded in a string
Powershell - Lesson 2
Types - The type is in `[]`. The Static Member Invocation operator is `::`. The Static method name is on the Right.
[guid]::NewGuid()
Switch (and assigning it to a variable)
Literal strings: `@" "@`
ConvertTo-Json / ConvertFrom-Json (LazyJsonExample.ps1)
New-Object
Creating custom classes `add-type @" public class
Invoke-RestMethod
Invoke-WebRequest (More work to get the entire response)
Talking to RavenDb
GRC Commandlets
Powershell - Lesson 3
" vs '
` - escape character (Line breaks, including " inside a double quoted string, `n for newline)
, operator: make an array: `$array = 1, 2, 3` or `$array = ,1` https://technet.microsoft.com/en-us/library/hh847732.aspx
. - Invoke operator
& - Call operator
param ( ... )
Functions
Writing commandlets
Modules
Paging Raven Results
Powershell - Lesson 4 (Guest speaker: Doug Lewis)
DSC - Desired State Configuration
Powershell - Lesson 5
UTF-8 Encoding
Updating raven documents
Powershell - Lesson 6
Remote scripting
Configure locally to allow outgoing scripts: (Run as admin)
> cd wsman:
> Set-Item .\localhost\Client\TrustedHosts -Value * #allows remote scripts to run on any destination
Configure remotely to allow Windows Remote Management:
> winrm quickconfig
> Enable-PSRemoting
> Invoke-Command -ComputerName goby-qa -ScriptBlock { $env:computername } -Credential dev\rborck
WMI Objects
[CmdletBinding], [Parameter(ValueFromPipeline=$true)]
Other notes:
Starting and monitoring Jobs? (DSC?)
Forgiving variable usage gotchas in powershell
$doug = 5
write "$($doog+5)"
Unzip a zip file:
$zip = $shell.NameSpace("C:\Provisioning\buildagent.zip")
$zip.items() | % { $shell.Namespace("$buildAgentBasePath").copyhere($_) }
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host
AD Commandlets, SQL CmdLets, Services CmdLets, MSMQ Cmdlets
Powershells version of Lamda's
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment