Determine if a command exists in your path. Very helpful when you are writing scripts for mulptiple machines.

$local:cmd = get-command doesnotexist -ea SilentlyContinue
if ( $null -eq $cmd )
{
  # Action if command does not exist
}
else
{
  # Action if command exists
}

This will get the directory holding the currently executing script

$local:scriptPath = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition)

Share Post

Google+

comments powered by Disqus