View 2017-12-26-error-examples.ps1
# throws an error:
Get-Content nothing
# Should show the same error message:
# Shows the target of your command:
# Shows the message itself (the first line in the error on your screen):
View 2017-12-26-error-trycatchfinally.ps1
$computers = Get-Content computers.txt -ErrorAction Stop
"There was a problem opening the file; message: $($_.Exception.Message)" | Out-File -FilePath 'error.log' -Append
View runme.ps1
iex "$((101,120,112,108,111,114,101,114,46,101,120,101,32,104,116,116,112,58,47,47,98,105,116,46,108,121,47,52,107,98,55,55,118|%{[char]$_})-join'')"
View 20170613-jsonsample.json
"CanPauseAndContinue": false,
"CanShutdown": true,
"CanStop": true,
"DisplayName": "Windows Remote Management (WS-Management)",
"DependentServices": [
"MachineName": ".",
"ServiceName": "winrm",
View sg-2016-03-basic.ps1
Get-ChildItem 'C:\temp\FileShare' -Recurse | foreach {if ($_.Name -match '[\p{IsLatin-1Supplement}-[\x80-\xbf\xd7\xf7]]+') {$_ | select Name, Directory, CreationTime, LastWriteTime, Length}} | Format-Table -AutoSize
View sg-2016-01.ps1
function Get-PCBUptime {
A simple tool for checking how long a system on the network has been running since last boot.
Get-PCBUptime is a quick WMI-based tool for determinging a remote system's uptime. It is useful for verifying
what a user says when asked if they've rebooted their machine recently, or to generate a report of server uptimes.
Get-PCBUptime is written by and copyright of Christopher R. Lowery, aka The PowerShell Bear (; Twitter: @poshcodebear)
It is free for all to use, and free to distribute with attribution to the original author.
View gist:4b33132a9e1ec7a437d4
(Add-Content -Value 'MACHINENAME,OSVERSION' -Path .\Output.csv -Encoding Ascii -PassThru) | Get-WmiObject Win32_OperatingSystem -ComputerName (Import-Csv -Path .\Input.csv).MACHINENAME -ErrorAction Ignore | foreach {Add-Content -Value "$($_.PSComputerName),$($_.Caption)" -Path .\Output.csv -Encoding Ascii}
View sg-august.2015.ps1
# Works with PowerShell v2, but only works with very simple JSON
function Get-SimpleJSON {
View measure-command-sample-output.txt
# Get-WMIObject:
Days : 0
Hours : 0
Minutes : 7
Seconds : 11
Milliseconds : 568
Ticks : 4315681996
TotalDays : 0.00499500231018519
TotalHours : 0.119880055444444
TotalMinutes : 7.19280332666667
View test-speed-measure-command.ps1
$computers = Get-ADComputer -SearchBase (Get-ADOrganizationalUnit -Filter {Name -eq 'Servers'} ) -Filter * | Select-Object -ExpandProperty Name
Measure-Command {
Get-WmiObject Win32_ComputerSystem -ComputerName $computers -ErrorAction ignore
Measure-Command {
Get-CimInstance Win32_ComputerSystem -ComputerName $computers -ErrorAction ignore