Getting Executable from Command Line

by Apr 29, 2014

Sometimes it becomes necessary to extract the command name from a command line. Here is a function that can do this:

And this is the code:

function Remove-Argument
{
  param
  (
    $CommandLine
  )
  
  $divider = ' '
  if ($CommandLine.StartsWith('"')) 
  { 
    $divider = '"'
    $CommandLine = $CommandLine.SubString(1)
  }
  
  $CommandLine.Split($divider)[0]
} 

Twitter This Tip! ReTweet this Tip!