Last active
June 8, 2023 15:28
-
-
Save gvlx/cd3954fe25120babb7ea161361ce8491 to your computer and use it in GitHub Desktop.
PowerShell helpers
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
<# | |
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