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
| <# | |
| Sample snippet to interact with the NTDS certificate store using windows APIs | |
| #> | |
| $source = @' | |
| using System; | |
| using System.Runtime.InteropServices; | |
| public static class StoreHelper | |
| { | |
| [DllImport("CRYPT32.DLL", EntryPoint="CertOpenStore", CharSet=CharSet.Auto, SetLastError=true)] |
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 Start-Script { | |
| <# | |
| .SYNOPSIS | |
| Launches a target script in a new process, passing through all parameters. | |
| .DESCRIPTION | |
| Launches a target script in a new process, passing through all parameters. | |
| Uses dynamic parameters to offer the same signature as the script itself. | |
| Uses the same powershell hosting application that executes Start-Script to start the new process. | |
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 Register-ShellExtension { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory = $true)] | |
| [string] | |
| $Name, | |
| [Parameter(Mandatory = $true)] | |
| [string] | |
| $Text, |
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
| $source = @' | |
| using System; | |
| using System.Runtime.InteropServices; | |
| namespace Shell | |
| { | |
| public static class Host | |
| { | |
| public static void DisableScreensaver() | |
| { | |
| NativeMethods.SetThreadExecutionState(ExecutionState.DisplayRequired); |
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
| $ExecutionContext.InvokeCommand.CommandNotFoundAction = { | |
| param ( | |
| [string] | |
| $CommandName, | |
| [System.Management.Automation.CommandLookupEventArgs] | |
| $Lookup | |
| ) | |
| if ($CommandName -match '^(\d+)[WD](\d+)$') |
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 Out-Default | |
| { | |
| <# | |
| .SYNOPSIS | |
| A wrapper for Out-Default, adding automatic caching to all output sent to screen. | |
| .DESCRIPTION | |
| A wrapper for Out-Default, adding automatic caching to all output sent to screen. | |
| Maximum capacity can be configured by setting $global:OutputCacheSize |
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
| New-Module -Name Test -ScriptBlock { | |
| function Get-Test1 | |
| { | |
| [CmdletBinding()] | |
| param () | |
| $var = 24 | |
| $depth = 0 | |
| try | |
| { |
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-ShellBuffer | |
| { | |
| [CmdletBinding()] | |
| param () | |
| try | |
| { | |
| # Define limits | |
| $rec = New-Object System.Management.Automation.Host.Rectangle | |
| $rec.Left = 0 |
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
| $scriptBlock = { | |
| Connect-Lab | |
| $id = "<id>" | |
| $labname = "wsFund$($id)" | |
| $domainName = "lab$($id).contoso.com" | |
| $labSources = 'C:\LabSources' | |
| $image = 'Windows Server 2016 Datacenter Evaluation (Desktop Experience)' | |
| New-LabDefinition -Name $labname -DefaultVirtualizationEngine HyperV | |
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
| #----------------------------------------------------------------------------# | |
| # Parameters # | |
| #----------------------------------------------------------------------------# | |
| # Path to a file with server names | |
| $servers = 'DC', 'AdminHost' | |
| # Whether errors should be ignored | |
| $ignoreErrors = $true |