Public/Assert-Tool.ps1
function Assert-Tool { param( [Parameter(Mandatory)][string]$ToolName, [switch]$SkipAssert ) If ($GlobalCachedToolResults.ContainsKey($ToolName)) { $Result = $GlobalCachedToolResults[$ToolName] } Else { $oldPreference = $ErrorActionPreference $ErrorActionPreference = 'stop' try { if(Get-Command $ToolName) { $Result = $GlobalCachedToolResults[$ToolName] = $true } } Catch { $Result = $GlobalCachedToolResults[$ToolName] = $false } Finally { $ErrorActionPreference=$oldPreference } } If ($Result -eq $true) { Write-Log "$ToolName exists" -Level Debug } Else { Write-Log "$ToolName don't exist" -Level Debug } If ($SkipAssert.IsPresent) { RETURN $Result } Else { Assert-Condition $Result "$ToolName exists" } } $GlobalCachedToolResults = @{} |