1

all,

I am trying to run a command in Power Shell and I am told the file does not exist as it stands right now for the Power Shell code. If I do the same in DOS, it finds the file and executes correctly. The only difference is that there is an additional open and closed double quote around the file name. Can this be done in Power Shell the same way? If so, how can this be done as I am not familiar with Power Shell.

DOS:

IF EXISTS F:\lvcecstos.CSV F:\LaserVault\ContentExpress\ContentExpress.exe /CID:1 /CSV:<b>"F:\lvcecstos.CSV"</b> /ClearSubscription

Power Shell:

Invoke-Expression -Command "F:\LaserVault\ContentExpress\ContentExpress.exe /CID:1 /CSV:<b>F:\lvcecstos.csv</b> /ClearSubscription"

Thanks in advance for any suggestions. I am told by the Laservault engineers that created this software package that we use that the double quotes around the file name is required. Doesn't make sense to me as to why though, but this is something I am unable to get around.

papanito
  • 2,349
  • 2
  • 32
  • 60
user3013729
  • 65
  • 2
  • 3
  • 7

3 Answers3

1

You can add double quotes around the file path as follows:

Invoke-Expression -Command 'F:\LaserVault\ContentExpress\ContentExpress.exe /CID:1 /CSV:"F:\lvcecstos.csv" /ClearSubscription';

Notice how the command is wrapped in single quotes instead of double quotes.

Ultimately, it depends on how the ContentExpress.exe program is interpreting the file path, though. For all you know, it could be appending the valued passed to "CSV" to the "current working directory."

You can also use the Start-Process cmdlet, instead of Invoke-Expression or Invoke-Command.

$Program = 'F:\LaserVault\ContentExpress\ContentExpress.exe';
$ArgumentList = '/CID:1 /CSV:"F:\lvcecstos.csv" /ClearSubscription';
Start-Process -Wait -NoNewWindow -FilePath $Program -ArgumentList $ArgumentList;
  • Thanks so much for the detailed explanation. It makes sense, even for this noob. I appreciate your assistance. Issue resolved for time being. Will confirm resolution when an end-user goes to process a fax file. – user3013729 Jan 13 '14 at 16:29
  • I also looked at the help file and found that there is an Invoke-Command cmdlet. Would I need to use that instead of the Invoke-Expression cmdlet? – user3013729 Jan 13 '14 at 15:54
1

If you have PowerShell v3 (which you should) you could use the "magic parameter" --% (see here).

& F:\LaserVault\ContentExpress\ContentExpress.exe --% /CID:1 /CSV:"F:\lvcecstos.csv" /ClearSubscription

Otherwise trying to preserve double quotes around arguments could become very, very painful. See for instance this answer to a similar question.

Community
  • 1
  • 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0
$lvcecstos = "F:\lvcecstos.CSV"
If(Test-Path $lvcecstos)
{
    Invoke-Expression -Command "& F:\LaserVault\ContentExpress\ContentExpress.exe /CID:1 /CSV:$lvcecstos /ClearSubscription"
}
T.CK
  • 411
  • 4
  • 6