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
powershell.exe -executionpolicy bypass -noninteractive -nologo -noprofile -command "&{ If (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {write-warning 'You must run this script as an Administrator!'; cmd.exe /c pause; exit 1000} }" | |
if ERRORLEVEL 1000 goto :EOF |
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
# But [datetime]::IsLeapYear is faster anyway | |
function Test-IsLeap ([uint32]$year) { | |
(($year * 1073750999) -band 3221352463) -le 126976 | |
} |
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 Convert-XmlToString { | |
param ( | |
[Parameter(Mandatory,ValueFromPipeline)] | |
$xml | |
) | |
begin { | |
$sw = [System.IO.StringWriter]::new() | |
$xmlSettings = [System.Xml.XmlWriterSettings]::new() | |
$xmlSettings.ConformanceLevel = [System.Xml.ConformanceLevel]::Fragment | |
$xmlSettings.Indent = $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 Wait-Task { | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[System.Threading.Tasks.Task] $Task, | |
[alias('wait')][int] $TimeOutMs = 1000 | |
) | |
begin {if ($TimeOutMs -lt 1) {$TimeOutMs = -1}} | |
process { | |
if ($task.AsyncWaitHandle.WaitOne($timeoutMs)) { | |
$task.GetAwaiter().GetResult() |
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-HtmlContent { | |
[CmdletBinding()] | |
[alias('ghc')] | |
param ( | |
[Parameter(Mandatory,ValueFromPipeLine)] | |
[Uri[]]$Uri, | |
[alias('ua')][string]$UserAgent, | |
[System.Text.Encoding]$Encoding, | |
[alias('wait')][int] $TimeOutMs = -1 | |
) |
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 Slice-String ([string]$string, [int]$length, [int[]]$part) { | |
if ($length -gt 1) { | |
if ($part.count) { | |
($string -split "(?<=.)(?=(?:.{$length})+$)")[$part] | |
} else { | |
$string -split "(?<=.)(?=(?:.{$length})+$)" | |
} | |
} else {$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 Invoke-PSCommand { | |
[CmdletBinding(DefaultParameterSetName='scriptblock')] | |
[alias('ipsc')] | |
param ( | |
[Parameter(Mandatory,Position=0,ParameterSetName='scriptblock')] | |
[ValidateNotNullOrEmpty()] | |
[alias('sb')][ScriptBlock] $ScriptBlock, | |
[Parameter(Mandatory,Position=0,ParameterSetName='file')] | |
[ValidateNotNullOrEmpty()] | |
[alias('fn')][string] $FileName, |
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
"C:\ProgramData\Microsoft\Windows\Start Menu\*.lnk", | |
"$($ENV:APPDATA)\Microsoft\Windows\Start Menu\Programs\*.lnk" | | |
Get-ChildItem -Recurse | ForEach-Object { | |
[PSCustomObject]@{ | |
Name = $_.baseName | |
Shortcut = $_.Fullname | |
} | |
} | Sort-Object Name |
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 Convert-EventLogRecord { | |
[cmdletbinding()] | |
[alias('clr','Format-EventLogRecord')] | |
param ( | |
[Parameter(Position=0,Mandatory,ValueFromPipeline)] | |
[ValidateNotNullOrEmpty()] | |
[alias('logrecord','events')] | |
[System.Diagnostics.Eventing.Reader.EventLogRecord[]]$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
function Use-Culture { | |
param ( | |
[System.Globalization.CultureInfo]$culture = (throw "USAGE: Use-Culture -Culture culture -Script {scriptblock}"), | |
[ScriptBlock]$script = (throw "USAGE: Use-Culture -Culture culture -Script {scriptblock}") | |
) | |
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture | |
trap { | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture | |
} | |
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture |
NewerOlder