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

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.

Related

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

Installing interactive msi in Remote Machine with Powershell

I have a .msi file in my remote machine which is in a different domain from my local machine. I am able to connect to the remote machine with powershell but how can I install the msi there. The installation process has a lot of inputs to be given along with pressing 'Next' and then again giving a particular input and radio buttons and many more. Thus it is an interactive installation. In my local I am able to do it with [System.Windows.Forms.SendKeys] to imitate the keyboard inputs but as the process will be running in background in the remote machine I don't think SendKeys will work. And 'psexec' is not an option here because in my remote machine I cannot include PSTools with my Powershell. Is there any way to do it with Invoke-Command and -ArgumentList??
If there is a way then how can I choose sequentially whether to input a text in a particular field or click the next button or click any other button within the application window??
I finally got to solve this puzzle with the help of a automation tool called AutoIt. This tool has its own scripting language and can create .exe files to run a particular application and do the corresponding installation steps based on each successive window the application installer pops. After creating the .exe I copied it to my remote machine using Copy-Item or you can use robocopy, then invoked the .exe remotely with the help of psexec. As I had the misconception previously about psexec, it only needs to be integrated with powershell at the local and thus it automatically creates a session of its own and interacts with the remote machine. This is the command to run the .exe on remote machine:-
psexec -i 2 -s -d \\remote_machine_name -u Username -p Password C:\Path_to_exe\installer.exe
You can actually log on to the remote machine and see in the GUI that it is happening. And yes, obviously you need to have the .msi which will be called to be present there in the remote machine so that the .exe can do its job locally in the remote session.

Unable to run a batch file(which calls a vbscript(which executes qtp script)) on a remote machine using 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 ??

How to copy a text file through command prompt from a source machine to a destination machine when they are on the same network?

How should I copy a text file say CopyMe.txt from a machine A to a machine B? These two machines are on the same network. Each of these 2 machines need a username and password to log into remotely. I want to achieve this copy action through command prompt.
I have tried using ROBOCOPY command and here is what I have tried step by step:
Get the IP address of machine B say a.b.c.d
Log into machine A and open command prompt
Say the CopyMe.txt file is present on machine A's desktop. So I type the following: ROBOCOPY C:\Users\user_name\desktop\CopyMe.txt \a.b.c.d\C$\Users\user_name\desktop
I get the following error saying Error 5 (0x00000005) Getting File System Type of Destination \a.b.c.d\C$\Users\user_name\desktop\ Access is denied

executing win32ole script on remote windows machine through telnet

I am trying to create a word document on a remote windows machine. What I am trying is to telnet to the remote windows machine and run a perl script that creates word document through Win32::OLE. But it doesn't seem to work. Is this possible? Because my script has {visible} set to 1 but will that telnet session have access to instances of word application? Atleast I tried it didn't work.
Telnet may not be the best tool to accomplish this, I'm not sure what kind of permissions it has. I recommend using PsExec, which allows remote command execution on windows servers. If it works locally, it will work using PsExec.
For example:
PsExec.exe \\remotecomputer -u userName -p Password Perl C:\path\to\file\file.pl
You can use the -s flag to run as system account, and the -i flag to run it interactively on the desktop. Without the -i flag, it will run in the console session.