This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Show-AutoComplete { | |
[CmdletBinding()] | |
param ( | |
[ValidateSet('Apple','Orange','Banana','Kiwi','Strawberry')] | |
[string] $Fruit = 'Apple' | |
) | |
Write-Host "The chosen value is [$Fruit]" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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!" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-WmiObjectTimeout { | |
<# | |
.SYNOPSIS | |
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 | |
parameter | |
.PARAMETER Class |