Loop | Return | Continue | Break |
---|---|---|---|
Normal Expectation | Exit Scope | Next Item | Exit Loop |
.foreach{} | Next Item | Break Scopes / Next Item of Parent Loop | Break Scopes / Exit Parent Loop |
foreach ($y in $x) | Exit Scope | Next Item | Exit Loop |
for ($i;$i -lt 5;$i++) | Exit Scope | Next Item | Exit Loop |
Foreach-Object -InputObject @() | Next Item | Break Scopes / Next Item of Parent Loop | Break Scopes / Exit Parent Loop |
Switch | Exit Scope | Next Item | Exit Switch |
While |
This file contains hidden or 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
# Copyright: (c) 2021, Jordan Borean (@jborean93) <[email protected]> | |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | |
class EncodingTransformAttribute : Management.Automation.ArgumentTransformationAttribute { | |
[object] Transform([Management.Automation.EngineIntrinsics]$engineIntrinsics, [object]$InputData) { | |
$outputData = switch ($InputData) { | |
{ $_ -is [Text.Encoding] } { $_ } | |
{ $_ -is [string] } { | |
switch ($_) { |
This file contains hidden or 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
# Copyright: (c) 2021, Jordan Borean (@jborean93) <[email protected]> | |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | |
Function Get-ServiceCertStore { | |
<# | |
.SYNOPSIS | |
Open an X509 store to a service account. | |
.DESCRIPTION | |
Opens an X509 store to the NT SERVICE account specified. The X509 store can be used to then add/remove/enumerate |
This file contains hidden or 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
class MagicNumber | |
{ | |
hidden [int] $_value | |
MagicNumber([int]$value) | |
{ | |
$this._value = $value | |
} | |
# ECMA-335 I.10.3.2 |
This file contains hidden or 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
using namespace System.Management.Automation | |
# Use of StopUpstreamCommandsException is obviously not supported. Subject to breaking at any time. | |
function Select-FirstObject { | |
[Alias('first', 'top')] | |
[CmdletBinding(PositionalBinding = $false)] | |
param( | |
[Parameter(ValueFromPipeline)] | |
[psobject] $InputObject, |
This file contains hidden or 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
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]> | |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | |
Function Get-FtpFile { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$true)] | |
[System.Uri] | |
[Alias('Uri')] | |
$FtpUrl, | |
This file contains hidden or 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-XmlFileTreeAppend | |
{ | |
param( | |
[Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] | |
[string[]] | |
${Path}, | |
[Parameter(ParameterSetName='LiteralPath', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] | |
[Alias('PSPath')] | |
[string[]] |
This file contains hidden or 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 Test-RpcPort { | |
<# | |
.SYNOPSIS | |
Enumerates and tests connectivity to the RPC ports on the target server. | |
.DESCRIPTION | |
Enumerates and tests connectivity to the RPC ports on the target server. | |
Rebuilt from https://gallery.technet.microsoft.com/Test-RPC-Testing-RPC-4396fcda | |
#> |
This file contains hidden or 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
# Copyright: (c) 2020, Jordan Borean (@jborean93) <[email protected]> | |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | |
Function Invoke-WithImpersonation { | |
<# | |
.SYNOPSIS | |
Invoke a scriptblock as another user. | |
.DESCRIPTION | |
Invoke a scriptblock and run it in the context of another user as supplied by -Credential. |