Skip to content

Instantly share code, notes, and snippets.

Chris Dent indented-automation

View GitHub Profile
View Get-ArgumentCompleter.ps1
function Get-ArgumentCompleter {
<#
.SYNOPSIS
Get custom argument completers registered in the current session.
.DESCRIPTION
Get custom argument completers registered in the current session.
By default Get-ArgumentCompleter lists all of the completers registered in the session.
.EXAMPLE
Get-ArgumentCompleter
View ConvertTo-NormalizedString.ps1
function ConvertTo-NormalizedString {
<#
.SYNOPSIS
Attempts to replace diacritics within a the input string.
.DESCRIPTION
Uses String.Normalize to attempt to replace diacritic characters within a string.
#>
[CmdletBinding()]
param (
@indented-automation
indented-automation / Get-CommandParameter.ps1
Last active Jan 11, 2019
PowerShell version 2 param block parser
View Get-CommandParameter.ps1
function Get-CommandParameter {
# .SYNOPSIS
# A PowerShell version 2 compatible parameter block parser.
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 1, ValueFromPipelineByPropertyName = $true)]
[String]$Definition
)
View Get-IniFileItem.ps1
function Get-IniFileItem {
<#
.SYNOPSIS
Get an item from an Ini file.
.DESCRIPTION
Reads an Ini file, returning matching items.
The ini file items returned by this function include an Extent property which describes the location of an item within the file.
.EXAMPLE
Get-IniFileItem -Path somefile.ini
@indented-automation
indented-automation / Clean-File-Demo.ps1
Last active Oct 11, 2018
Removes trailing null data from the end of a file
View Clean-File-Demo.ps1
$Path = 'c:\temp\test.long'
$content = [Byte[]]::new(50MB)
[Array]::Copy(
[Byte[]][Char[]]'Hello world',
0,
$content,
10,
11
)
View NetApi.cs
namespace NetApi
{
using System;
using System.Runtime.InteropServices;
internal enum NetApiStatus : uint
{
NERR_Success = 0,
NERR_InvalidComputer = 2351,
NERR_NotPrimary = 2226,
View Get-WhoIs.ps1
function Get-WhoIs {
<#
.SYNOPSIS
Get a WhoIs record using servers published via whois-servers.net.
.DESCRIPTION
For IP lookups, Get-WhoIs uses whois.arin.net as a starting point, chasing referrals within the record to get to an authoritative answer.
For name lookups, Get-WhoIs uses the whois-servers.net service to attempt to locate a whois server for the top level domain (TLD).
Get-WhoIs connects directly to whois servers using TCP/43.
View Splatting.ps1
# Parameters used to authenticate remote connections
$remoteParams = @{
Credential = Get-Credential
ComputerName = $env:COMPUTERNAME
}
# Parameters which are specific to Test-WSMan
$testWSMan = @{
Authentication = 'Default'
ErrorAction = 'SilentlyContinue'
}
@indented-automation
indented-automation / Get-CommandParameter.ps1
Created Jul 28, 2018
Gets the parameters for a command from the default parameter set
View Get-CommandParameter.ps1
function Get-CommandParameter {
param (
[Parameter(Mandatory = $true)]
[String]$Command,
[Switch]$GetDefaultValues
)
$commonParameters = ([System.Management.Automation.Internal.CommonParameters]).GetProperties().Name
$shouldProcessParameters = ([System.Management.Automation.Internal.ShouldProcessParameters]).GetProperties().Name
$defaultParams = $commonParameters + $shouldProcessParameters
@indented-automation
indented-automation / Get-StrictMode.ps1
Last active Aug 2, 2018
Gets the strict mode version for the current scope
View Get-StrictMode.ps1
function Get-StrictMode {
[CmdletBinding()]
param (
[Switch]$All
)
[Reflection.BindingFlags]$flags = 'Instance, NonPublic'
try {
# SessionStateInternal
You can’t perform that action at this time.