Unable to invoke PSEXEC on remote machine using ActiveBatch - batch-file

I am trying to execute a bat file on a remote computer using psexec through ActiveBatch and getting the rejection:
"Could not start PSEXESVC service on 'remote machine', Activity
'ShellCommand' failed, ApplicationException in step 'ShellCommand':
Process exited with '2250'".
To run access the remote .bat I am using a ShellCommand step with the following command:
psexec -u admincred -p pass -i 2 -d \remotecomputer cmd /c c:\msg.bat
I believe the path is correct since the bat file is on the c: drive and will execute if the psexec command is run through cmd on my machine. All the .bat does is call a message to another remote computer.
I believe the problem is getting psexec to run through the ActiveBatch ShellCommand on the remote machine.

I do not know anything about ActiveBatch. But, if you can specify a command line, could you use something like this and not need psexec.exe?
powershell -NoProfile -Command "Invoke-Command -ComputerName HOST001-ScriptBlock { & cmd.exe /C C:\Temp\msg.bat }"
A shortened form would be:
powershell -NoProfile "Invoke-Command HOST001 { & cmd.exe /C C:\Temp\msg.bat }"
If you must run the script as a different user, Invoke-Command has a -Credential parameter that can be used.

Related

Run bat file as admin remotely in cmd prompt for user on network

I've tried uses psexec but all it does is start the process in the background and gives it an ID but doesn't actually do anything.
Attempts:
psexec \\pc -h -u org\user -p pass -d -i cmd copy "first_location" "<into_this_locat>"
psexec \\pc -h -u org\user -p pass command copy "first_location" "<into_this_locat>"
It's important that I run this command as an admin otherwise it won't work.
Maybe I can run a .bat file after connecting to their computer as admin?
A sustainable way to do this without the need for additional programs to be installed is by using PowerShell. If you are on a supported Windows system, PowerShell will be available.
If you must run from a cmd.exe shell, the following can be used.
powershell -NoLogo -NoProfile -Command ^
"Invoke-Command -ComputerName 'SERVER01' -ScriptBlock {Copy-Item -Path "$Env:USERPROFILE\y.y" -Destination "$Env:USERPROFILE\x.x"}"

Display Batch file output message in local machine

I am using psexec tool to run a batch file in remote machine. Everything is good except that I am unable to see any batch output messages that we usually see in cmd window. I want these msgs on my local machine psexec shell window. Is there anyway to do that?
I am using the command as:
psexec -u admin -p tool#321 \\10.189.21.19 -s -d cmd.exe /c "C:\TEMP\output\batch_script.bat"
What about creating an admin share and outputting the data there?
psexec -u admin -p tool#321 \10.189.21.19 -s -d cmd.exe /c "C:\TEMP\output\batch_script.bat >\\server\logs$\10.189.21.19.txt"

PSEXEC: not recognising remote command

I am able to execute basic operation by triggering batch script on remote location using following command.
psexec -e -h -s -u User -p pass \\10.0.0.240 C:\test.bat
But when the test.bat file is calling other program specific script like somepy.py then I am getting error on master batch file that these are not internal command.
Master batch file in Host computer:
CODE
psexec -e -h -s -u user -p pwd \\10.0.0.240 C:\Users\Desktop\TEST\test.bat
Command inside test.batlocated in remote PC:
cd C:\Users\Desktop\TEST1
impact -batch test_impact_warp_AP.cmd
`pause`
waitfor /t 5 StartNow
REM wait for 5second
echo "Run python script for Warp"
cd C:\Users\Desktop
call warp-python.bat
ipconfig /all
ping google.com
Command inside warp-python.bat present in remote machine:
set PYTHONPATH=C:\Users\Desktop\Python_Reference
cd C:\Users\Desktop\Python_Reference\examples\PYTHON_SCRIPT
python t_capture.py
When I executed the test.bat script directly then warp-python.bat as well as test_impact_warp_AP.cmd executes perfectly without any error.
But when i try to execute test.bat from remote location then *python* and *impact* commands are not recognised. and gives following error:
'Impact' is not recognised as an internal or external Command
But ipconfig/all and ping command is executed perfectly in remote PC
What am I missing in the command line argument such that psexec in not able to executed the command in remote location
Add the psexec.exe to your PATH variable in the environment variable or
give the full path of psexec.exe in your command.
Example:
c:\users\test\Desktop\psexec.exe -e -h -s -u User -p pass \10.0.0.240 C:\test.bat
Make sure C:\test.bat is present in your remote machine.

Psexec to execute batch file,which calls a vbscript,and this vbscript executes test case using qtp on a remote machine

Scenario :
System 1(Remote Machine) :
"abc.bat"
"xyz.vbs"
Both the files are in D Drive
Scenario : "abc.bat" calls "xyz.vbs" and the command is like this: cscript D:\xyz.vbs
"xyz.vbs has script which calls QTP and executes the test script on QTP.
System 2(My Machine) :
I have downloaded PSTools and making use of Psexec command to execute batch file on above remote machine.
In my cmd i have this command.
C:\Program Files\PSTools>psexec -i \System_1's_IP_address -u domain\username -p password D:\abc.bat
When i run this command on my machine, it starts PSexec on remote machine. But QTP is not invoked on the remote machine so execution halts here.
I have checked in task manager.it shows wscript,psexec.
But not QTPro.exe
Is there a solution??
Can somebody please help.
PSEXEC \\<Targetsystem> -u domain\username -p password -i -w D: cmd.exe /c abc.bat
or
place the abc.bat in the same folder as psexec and execute this one:
PSEXEC \\<Targetsystem> -u domain\username -p password -i -c -f abc.bat
(P.S.: a look at PSEXEC /? may help ;))

Powershell RDP Session and CLI Script

What I am looking to do seems fairly simple but I cant figure it out. I am looking to run a Powershell script to launch an RDP session, copy a file to the c:\ directory, then run that file from a command line. I would like it to loop, getting the paramaters froma csv file, such as server IP, username, and password. So in essence the steps would be as follows...
import infor from the csv file to define variables
copy specefied file
(then loop)
launch mstsc.exe
enter server IP, username, password
paste copied file into the c:\ directory
launch cmd.exe
Run the file that was copied to the c:\ directory
log off server
I wanted to see if someone could help me out with this.I am new to power shell and have been able to work through a lot of it. If someone could point me in the right direction, or even provide me the code to fill in the blanks, I would greatly appreaciate it.
I have done remote installs using psexec. psexec \\servername -u domain\usernamr -p password cmd /c "msiexec /i program.msi
PSexec download: https://learn.microsoft.com/en-us/sysinternals/downloads/psexec
This means instead of RDP you will use psexec to run the install remotely.
I have created a small PowerShell script to get you started. So let's assume your CSV file (c:\info.csv) has three columns ServerName, UserName, Password.
Run the below code, and it should work but make sure the change the first 4 lines as per your environment. Start by putting one server to observe the script behavior.
# Set intial variables
$CSVFile = "c:\info.csv"
$MSI = "\\servername\sharename\setup.msi"
$MSILog = "c:\Windows\temp\setup.log"
$Domain = "YourDomain"
# Import info from CSV file
$Servers = import-csv $CSVFile
# loop through each server
foreach ($server in $servers) {
# run psexec on each server to install a program
psexec \\$server.servername -u $Domain\$server.username -p $server.password -h cmd /c "msiexec /i $MSI /quite /l*v $MSILog"
}
I recommend you using this command because I don't exactly what you are trying to do.
Get-help Import-CSV
Get-help about_remoting this will avoid doing the mstsc.exe thing for you.
Enter into the session and Invoke-Command against this session and you can run commands on that server.
$session = New-PSSession -ComputerName Server1 -Credentials Get-Credential
Invoke-Command -Session $session -ScriptBlock {
}
Inside the Script block specify you powershell command to copy files and run them.

Resources