I have a PowerShell script that needs to run under multiple hosts (PowerGUI, PowerShell ISE, etc...), but I am having an issue where sometimes a cmdlet doesn\'t exist under one
This is a simple function to do what you're like to do :)
function Check-Command($cmdname)
{
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
How to use (for example):
if (Check-Command -cmdname 'Invoke-WebRequest')
{
Invoke-WebRequest $link -OutFile $destination
}
else
{
$webclient.DownloadFile($link, $destination)
}