Unable to run a batch file(which calls a vbscript(which executes qtp script)) on a remote machine using psexec - psexec

The scenario is like below :
abc.vbs file - contains call to QTP,which executes test scripts.
xyz.bat file - contains call to abc.vbs
when i run xyz.bat in remote machine in a command prompt,it works perfectly.
When i run using PSExec on my local machine with the following command,it wont run.
E:/FolderName>PSExec -i //remote machine name -u (username) -p (password) complete path of file/xyz.bat
It says file exited with error code 0.
But in remote server nothing would have happened.
Can somebody help me in this case ??

Related

PSEXEC command runs correctly on remote computer but redirecting data back to source computer results in user name or password incorrect

I have run the PSEC command successfully on my old WIN 10 computer for years. Recently I had to buy a new computer running WIN 11. The PSEC command runs successfully on new computer with return code 0 but the redirect commands to return data to source computer results in error "The user name or password is incorrect. Shown below is the PSEC command I run.
C:\Windows\System32>c:\windows\system32\psexec \\main -h -f -accepteula -u main\abc -p xyz -c "c:\users\123\documents\backup\Log_enable_Main.bat"
An extract of Log_enable_Main.bat is below:
hostname
hostname >> \\ShopNew\users\123\documents\backup\logenable.log
And the execution of that command results in:
C:\WINDOWS\system32>hostname
Main
C:\WINDOWS\system32>hostname 1>>\\ShopNew\users\123\documents\backup\logenable.log
**The user name or password is incorrect.**
I don't even know what user name or password it refers to. Like I indicated the bat file runs correctly on remote computer. It executes several commands on the remote and saves the data locally it just won't send data back to the source computer. I have credentials on both computers that points to the other computer. I am at a loss where to begin.
As indicated above, this command has run successfully for years on my old WIN 10 computer I just can't get it to work on my WIN 11. The remote computer is still running WIN 10.

How to execute ssh connect by script?

I have local Windows 10 and remote Ubuntu server.
I want to automate connection to server and write executable script witch connects by ssh to server and open new terminal from another server.
What it's supposed to look like
I double click on bat
And then script
inits ssh connect
writes password
gives the user a terminal with a ready ssh connection.
That is, it mimics the following
Problems
How to wait ssh password request? All commands executes immediately.
(additional) can I write it in .sh script, run script, execute all in "start" terminal (from which I run .sh script) and then pass ssh control to invoked terminal?
It's best if someone writes a ready-made script
Automatically enter SSH password with script
Answers:
Direct answer - use expects. But sshpass is better. Also RSA-key can be used.
Can`t tell anything.
Can be done without any 3rd party tools like this:
$env:TMPPW=Get-Content -Path 'secure_file.txt' ; $un='MyUserName'
$j=Start-Job -ScriptBlock{Start-Sleep -Seconds 1
(New-Object -ComObject wscript.shell).SendKeys("$env:TMPPW{ENTER}")}
& ssh.exe -q -4 -l $un 127.0.0.1 'whoami'
$env:TMPPW=([guid]::NewGuid()).Guid ; $env:TMPPW=$null

Noninteractive Remote Commands with Powershell

I am developing a script which uses ssh to connect to a windows host, run a powershell command, and parse the output. While I can connect to the host and run the command, powershell will not exit and return control back to the local script until I press the enter key.
At the moment, the specific command being run is ssh HOSTNAME 'echo $(hostname)' and the ssh server is configured to pass remote execution requests to powershell -noninteractive -command CMD, where HOSTNAME is the name of the windows host and CMD is the remote command to be run (in this case echo $(hostname)).
The end goal is to have the script which is calling remote powershell commands to run completely noninteractively, but this is currently impossible as the powershell command will not run noninteractively.
How do I get powershell to run remote commands noninteractively?
I've resolved the issue. While I haven't determined what was causing the issue, I can at least overcome the issue at hand by redirecting stdin to /dev/null on the side that initiates the ssh connection.
$ ssh HOSTNAME "CMD" </dev/null
This solution doesn't involve powershell at all, but rather treats the symptoms from the other side of the connection.

Using Netsh with PsExec

I'm trying to dump DHCP settings from an older server thats being decommissioned. I ran the command fine while on the actual server but when trying to run it using psexec remotely, it keeps failing. The command is: psexec \\$source netsh dhcp server \\$source dump>$dhcpSettings
$source = the server being decommissioned
$dhcpSettings = the path to save the dumped settings
I've tried all sorts of combinations of encapsulating quotation marks but still nothing. the errors I'm getting is, "The system cannot find the file specified" and "The system cannot find the path specified"
EDIT: So I got rid of the path to save the dumped settings and now it works. But how should I format the command so that it'll save the settings to the remote computer's C:\USER.SET\LOG directory?
One solution might be to bundle the command you want to run and the stdout redirection into a single line cmd file and use PsExec -c or -f to copy and execute that file on the remote system. As an example
Create a line cmd file named DHCPSettings.cmd with the following in it and save it to C:\temp\:
netsh dhcp server \\localhost dump >c:\user.set\log\dhcpsetting.log
Then use
psexec \\$source -c c:\temp\DHCPSettings.cmd
You did not really provide any code to go by and I am not sure I understand the all requirements and constraints you have, so consider this as an idea; not the exact commands you need to run. Hope it helps.

Copy a non exe File to a Remote Machine

I used PsExec to copy and run an exe file in a remote machine. I also want to copy a xml file to remote machine. I am able to do this way
PsExec.exe -d -c \\someserver c:\somefile.xml
The above command throws error saying system cannot find the file specified but adds the xml file to remote server.
Do u know any better way of copying files to remote server.
Is there any PsTool available for that?
Or an option in PsExec ?
Edit: (Answer)
I found out that using Powershell we can copy file to remote machines and it worked.
As you can read from psexec help
-c: Copy the specified program to the remote system for execution. If you omit this option the application must be in the system path on the
remote system.
So your xml file is copied on remote sys/USER:[domainname]username]tem and executed, this gives you the error.
If your xml is part of an application you have to run in remote computer, one solution is compress the app with all necessary files in a self-extracting EXE that runs main command when extracted.
If you just have to copy a file, why don't you use a simple script that maps remote folder and then copies file? Something like:
NET USE \\computername\sharename password /USER:[domainname\]username
xcopy .....
NET USE \\computername\sharename /DELETE
PsExec is not designed to copy files across machines. It can only copy the program it is going to run remotely.
If you have access to the remote machine, the copy could be done by running copy c:\somefile.xml \\\\remote-machine\Admin$ before running PsExec.
You can use this pattern with psexec to copy any extension ...
psexec -d -i 2 \PC Name -u domain\username -p password cmd /c copy
\server\location\filename c:\xx\xx\xx
PS: Refer to PSEXEC switches if you're unsure of what -d and i does. However "2" is a session id of remote desktop user that may change every time a new remote desktop session is created.
this helped me copy my exe file into c:\windows directory (one to one copy within same domain) :
PsExec.exe -d -c \\remoteserver -u administrator -p password c:\executable.exe