Skip to content

Instantly share code, notes, and snippets.

@gvlx
Last active June 8, 2023 15:28
Show Gist options
  • Save gvlx/cd3954fe25120babb7ea161361ce8491 to your computer and use it in GitHub Desktop.
Save gvlx/cd3954fe25120babb7ea161361ce8491 to your computer and use it in GitHub Desktop.
PowerShell helpers
<#
PowerShell one-liner helpers
#>
# find non-existent paths in current $PATH
# From https://stackoverflow.com/a/65505792/43408
($env:path).Trim(";").Split(";") | ? {-not (test-path $_ -ErrorAction Ignore)}
# simple file test
function Test-If-File-Exists {
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
[String] $FileName
)
Write-Debug "Test existence of $FileName."
if (!(Test-Path $FileName -PathType Leaf -ErrorAction Ignore)) {
throw (New-Object System.IO.FileNotFoundException("File not found: $FileName", $FileName));
}
}
# equivalent Write-Debug for Format-Table
function Format-Table-Debug {
param(
[Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
$InputObject
)
Format-Table -InputObject $InputObject | Out-String -Stream | Write-Debug
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment