Trying to pass variables to a command line exe

Ask your 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.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
simon.briggs
Posts: 10
Last visit: Mon Feb 01, 2021 6:18 am

Trying to pass variables to a command line exe

Post by simon.briggs »

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}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trying to pass variables to a command line exe

Post by jvierra »

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.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked