Utils.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# General Utility Functions function Invoke-NullCoalescing { $result = $null foreach($arg in $args) { if ($arg -is [ScriptBlock]) { $result = & $arg } else { $result = $arg } if ($result) { break } } $result } Set-Alias ?? Invoke-NullCoalescing -Force function Get-LocalOrParentPath($path) { $checkIn = Get-Item -Force . if ($checkIn.PSProvider.Name -ne 'FileSystem') { return $null } while ($checkIn -ne $NULL) { $pathToTest = [System.IO.Path]::Combine($checkIn.fullname, $path) if (Test-Path -LiteralPath $pathToTest) { return $pathToTest } else { $checkIn = $checkIn.parent } } return $null } function dbg ($Message, [Diagnostics.Stopwatch]$Stopwatch) { if($Stopwatch) { Write-Verbose ('{0:00000}:{1}' -f $Stopwatch.ElapsedMilliseconds,$Message) -Verbose # -ForegroundColor Yellow } } |