Skip to content

Instantly share code, notes, and snippets.


Ryan Leap ryan-leap

View GitHub Profile
ryan-leap / Get-ProcessAncestry.ps1
Created October 24, 2020 13:24
Shows info about the current process, and it's parent, and it's parent...
View Get-ProcessAncestry.ps1
$processId = $PID
do {
$thisProcess = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $processId"
$thisProcess | Select-Object ProcessId,ParentProcessId,Name,CreationClassName,CreationDate,CommandLine
$processId = $thisProcess.ParentProcessId
} while ($null -ne $processId)
View AutoCompleteExample.ps1
function Show-AutoComplete {
param (
[string] $Fruit = 'Apple'
Write-Host "The chosen value is [$Fruit]"
ryan-leap / Get-ExceptionErrorType.ps1
Last active February 2, 2020 16:20
Get the error type of an exception (so you can write code to catch that particular exception)
View Get-ExceptionErrorType.ps1
# Quick bit of code to get the error type of an exception so that
# you can write code to catch that particular exception
Try { 1 / 0 } Catch { "Exception Error Type is: [$($_.Exception.GetType().FullName)]"}
# Running the above:
# Exception Error Type is: [System.Management.Automation.RuntimeException]
# Now use the output to catch that specific error type
Try { 1 / 0 } Catch [System.Management.Automation.RuntimeException] { "Caught it!" }
ryan-leap / Get-WmiObjectTimeout.ps1
Created November 2, 2019 16:30
Get-WmiObject with a timeout
View Get-WmiObjectTimeout.ps1
Function Get-WmiObjectTimeout {
Get-WmiObject call with a timeout
.PARAMETER ComputerName
Specifies the target computer for the management operation
.PARAMETER Namespace
Specifies the WMI repository namespace where the specified WMI class is located when used with the Class