Zahid Ahamed
asked on
How to run windows batch file remote computer
Hi,
I want to run a windows batch file on a remote computer using PowerShell. I have tried with this following command but didn't work.
Invoke-Command -ComputerName "ccccccc" -credential domain\xxxx -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /E 'E:\_deployment\ServicePac k\Install_ ServicePac k.bat'"}
Please help
I want to run a windows batch file on a remote computer using PowerShell. I have tried with this following command but didn't work.
Invoke-Command -ComputerName "ccccccc" -credential domain\xxxx -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /E 'E:\_deployment\ServicePac
Please help
If you have an AD domain you can add scripts as logon scripts
What exactly did not work? Do you get an error?
There are two obvious errors here.
One is the /E - this is the argument to enable/disable command extensions, and it expects ":On" or ":Off" afterwards. What you need (probably instead of /E) is /C to run the command and then close the shell.
Then you can't use single quotes in a cmd.exe command line - this works in PS only, not in cmd.exe.
The Invoke-Expression is not required at all.
Try
One is the /E - this is the argument to enable/disable command extensions, and it expects ":On" or ":Off" afterwards. What you need (probably instead of /E) is /C to run the command and then close the shell.
Then you can't use single quotes in a cmd.exe command line - this works in PS only, not in cmd.exe.
The Invoke-Expression is not required at all.
Try
Invoke-Command -ComputerName "ccccccc" -Credential domain\xxxx -ErrorAction Stop -ScriptBlock {& cmd.exe /C "E:\_deployment\ServicePack\Install_ServicePack.bat"}
ASKER
I have received an error.
The system cannot find the path specified.
+ CategoryInfo : NotSpecified: (The system cann...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : cccccccccccccccccccc
The system cannot find the path specified.
+ CategoryInfo : NotSpecified: (The system cann...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : cccccccccccccccccccc
Well, what the message says: the path "E:\_deployment\ServicePac k\Install_ ServicePac k.bat" does not exist on cccccccccccccccccccc ...
ASKER
Invoke-Command -ComputerName cccccc -Credential Domain\xxx -ScriptBlock {& cmd.exe cd e \ "E:\_deployment\ServicePac k\Install_ ServicePac k.bat"}
After execute this above command using run as administrator it says completed but don't see any action
After execute this above command using run as administrator it says completed but don't see any action
Because all you're doing with that command is a "cd". Use the exact syntax I posted above; don't add arbitrary commands to the command line.
ASKER
I ran this but I have received the below error:
Invoke-Command -ComputerName ccccc -Credential Domain\xxx -ScriptBlock {& cmd.exe /C "E:\_deployment\ServicePac k\Install_ ServicePac k.bat"}
The system cannot find the path specified.
+ CategoryInfo : NotSpecified: (The system cann...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : cccccccccccccccccccc
My guess is the batch file is in my local computer E:\ drive. Should I put the batch file in the remote computer or the local computer?
Thanks
Invoke-Command -ComputerName ccccc -Credential Domain\xxx -ScriptBlock {& cmd.exe /C "E:\_deployment\ServicePac
The system cannot find the path specified.
+ CategoryInfo : NotSpecified: (The system cann...path specified.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : cccccccccccccccccccc
My guess is the batch file is in my local computer E:\ drive. Should I put the batch file in the remote computer or the local computer?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You