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
$PrintWindowCode = @' | |
using System; | |
using System.Runtime.InteropServices; | |
using System.Drawing; | |
using System.Drawing.Imaging; | |
public class ScreenCapture | |
{ | |
[DllImport("user32.dll")] | |
public static extern bool GetWindowRect(IntPtr hWnd, out Rect lpRect); |
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
$map = @{ | |
color = 'red' | |
person = @{ | |
firstname = 'Bob' | |
lastname = 'Smith' | |
} | |
gender = 'his' | |
} | |
$template = @' |
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
$func = Invoke-RestMethod https://gist.githubusercontent.com/santisq/bd3d1d47c89f030be1b4e57b92baaddd/raw/73952eceb82cd31b8cb9f2fd04e2a3ef3c428110/Measure-Expression.ps1 | |
. ([scriptblock]::Create($func)) | |
time -TestCount 5 -OutputAllTests @{ | |
'TestUpdateTypeData' = { | |
class TestUpdateTypeData { | |
hidden [int] $_x | |
hidden [int] $_y | |
TestUpdateTypeData([int] $x, [int] $y) { |
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
Import-Module ActiveDirectory | |
$func = Invoke-RestMethod https://gist.githubusercontent.com/santisq/bd3d1d47c89f030be1b4e57b92baaddd/raw/73952eceb82cd31b8cb9f2fd04e2a3ef3c428110/Measure-Expression.ps1 | |
. ([scriptblock]::Create($func)) | |
$adsi = { | |
$searcher = [adsisearcher]::new( | |
'(&(objectClass=user)(objectCategory=person))', | |
[string[]] @( | |
'DistinguishedName' | |
'userAccountControl' |
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
class AppRegistration { | |
[string] $DisplayName | |
[guid] $AppId | |
[guid] $Id | |
$CreatedDateTime | |
AppRegistration([hashtable] $app) { | |
$this.DisplayName = $app['DisplayName'] | |
$this.AppId = $app['AppId'] | |
$this.Id = $app['Id'] |
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
& { | |
[CmdletBinding(DefaultParameterSetName = 'A')] | |
param( | |
[Parameter(ParameterSetName = 'A')] | |
$ParamA = 'A', | |
[Parameter(ParameterSetName = 'B')] | |
$ParamB = 'B', | |
[Parameter(Mandatory)] | |
$ParamBoth | |
) |
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
class JwtAssertion { | |
[System.Security.Cryptography.X509Certificates.X509Certificate2] $Certificate | |
hidden [System.Text.Encoding] $encoding = [System.Text.Encoding]::UTF8 | |
hidden [hashtable] $claims = @{ | |
# exp: 5-10 minutes after nbf at most | |
exp = [System.DateTimeOffset]::UtcNow.AddMinutes(5).ToUnixTimeSeconds() | |
# jti: a GUID, unique identifier for the request | |
jti = [guid]::NewGuid().ToString() |
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
$stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes(@' | |
[ | |
{ | |
"DomainName": "example1.com", | |
"DomainNetBIOSName": "EXAMPLE1", | |
"IDRanges": [ | |
{ "RangeStart": 2000, "RangeEnd": 2999, "Attribute": "uidNumber", "AccountType": "Computer" }, | |
{ "RangeStart": 3000, "RangeEnd": 3999, "Attribute": "uidNumber", "AccountType": "MSA" }, | |
{ "RangeStart": 4000, "RangeEnd": 4999, "Attribute": "gidNumber", "AccountType": "Group" }, | |
{ "RangeStart": 5000, "RangeEnd": 5999, "Attribute": "uidNumber", "AccountType": "AdmAccount", "IDGeneration": { "Type": "Calculation", "RefDomain": null } }, |
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
$subIdContext = @{ | |
Stage = 'xxxxx-xxxxx-xxxxx-xxxx' | |
Prod = 'xxxxx-xxxxx-xxxxx-xxxx' | |
} | |
if ($connected.Count -ne 2) { | |
$connected = @( | |
Connect-AzAccount -Subscription $subIdContext['Prod'] -SkipContextPopulation | |
Connect-MgGraph | |
) |
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
$private:hash = @{ foo = 'bar' } | |
& { | |
$type = $ExecutionContext.SessionState.PSVariable.GetType() | |
$method = $type.GetMember('GetValueAtScope', [System.Reflection.BindingFlags] 'Instance, NonPublic') | |
$method.Invoke($ExecutionContext.SessionState.PSVariable, ('hash', 'global'))['foo'] = 'nope' | |
} | |
$private:hash |
NewerOlder