Trying to pass variables to a command line exe

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
simon.briggs
Posts: 5
Joined: Mon Jan 04, 2016 1:35 am

Trying to pass variables to a command line exe

Post by simon.briggs » Mon Dec 11, 2017 1:30 am

I'm trying to pass variables to openfiles.exe but it is failing. I've tested the same code from the powershell ISE and it works without issue.

Error:
ERROR: openfiles.exe : ERROR: Invalid ID.
MainForm.psf (490, 4): ERROR: At Line: 490 char: 4
ERROR: + openfiles.exe /disconnect /s SERVER /ID $fi
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (ERROR: Invalid ID.:String) [], RemoteException
ERROR: + FullyQualifiedErrorId : NativeCommandError
ERROR:f
ERROR: Type "OPENFILES /Disconnect /?" for usage.
ERROR:

ISE code:
$list = @(
"57951384"
"56718140"
)
foreach($fi in $list)
{ openfiles /disconnect /s Server /ID $fi}

User avatar
jvierra
Posts: 12399
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Trying to pass variables to a command line exe

Post by jvierra » Mon Dec 11, 2017 5:28 am

Invalid ID means that there is no file with that ID that is in the open state. Check the file ID exisits before trying to disconnect it.

Locked