Skip to content

Instantly share code, notes, and snippets.

@criography
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save criography/bb9b81cf1f0b72efe62f to your computer and use it in GitHub Desktop.

Select an option

Save criography/bb9b81cf1f0b72efe62f to your computer and use it in GitHub Desktop.
Powershell: testing if cli tool is installed
# Had no success with usual redirecting, so using this instead
#
# USAGE:
# isInstalled '[command]' '[test]'
#
# e.g. checking whether chocolatey is present
# $test = isInstalled 'choco -v' '^\d+\..*?$'
Function isInstalled([string]$trigger, [string]$match){
$ErrorActionPreference = "SilentlyContinue";
$output = iex $trigger;
$ErrorActionPreference = "Continue";
return [boolean]($output -match '^\d+\..*?$');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment