Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, June 12, 2017 4:08 PM
I need to launch a small number of (DOS-like) commands from my .ps1 script
The commands look like:
change user /install
c:\folder1\setup.exe
change user /execute
I created a simple .cmd file but i am unable to understand the right syntax to invoke it from my .ps1 file.
Can anybody please help?
Can I invoke instead each single command from my .ps1 script?
Regards
Mario
All replies (6)
Monday, June 12, 2017 4:20 PM ✅Answered | 1 vote
To invoke commands just put a ".\ before the file name
.\filename.BAT
Tuesday, June 13, 2017 6:31 AM ✅Answered | 1 vote
Hi Mario,
did you mean this?
Invoke-Command -ComputerName (Get-Content Servers.txt) -FilePath C:\Scripts\Sample.ps1 -ArgumentList change user /execute, change user /install
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].
Tuesday, June 13, 2017 9:24 AM ✅Answered | 1 vote
change user /install
c:\folder1\setup.exe
change user /execute
Can I invoke instead each single command from my .ps1 script?
The commands are part of PowerSHell and Windows: just type them at a prompt or add them to a ps1 file.
You can type this for any command to see if it is available in PowerShell
Get-Command change
All EXE files are available to PowerShell or in a PowerShell script.
\(ツ)_/
Monday, June 12, 2017 4:19 PM
In PowerShell just type
c:\path\file.cmd
Have you even tried anything?
\(ツ)_/
Thursday, June 15, 2017 2:16 AM | 1 vote
Hi Mario
did you have any updates for this issue?
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].
Friday, June 16, 2017 2:49 PM
First of all, many thanks tio everybody.
I think I solved the problem by using a syntax like:
cmd /c 'change user /install'
cmd /c 'c:\folder1\setup.exe'
cmd /c 'change user /execute'
The only problem I see, at the moment, is that the result of the commands look to dirthy the Return code of the script block containing the code.
But it's a problem I need to investigate.
Many thanks, by now
marius