When I run this command locally on a remote machine it works:
powershell -Command "(New-Object Net.WebClient).DownloadFile('<WebPath>', 'C:\Users\<user>\Desktop\file.exe')"
When I try the same command remotely using PsExec in a batch file:
(Set downloadFileCommand = powershell -Command "(New-Object Net.WebClient).DownloadFile('%WebPath%', 'C$\Users\<user>\Desktop\file.exe')")
PsExec.exe \\<remote_machine> -u %username% -p %password% -s -d cmd /c %downloadFileCommand%
I am getting "cmd started on remote_machine with process ID #id_number."
However, nothing happened and the download wasn't executed. The suggestions here: Run PowerShell scripts on remote PC
didn't work for me.
Any suggestions?
Edit:
I managed to download the file through the command line (in cmd) using this command:
PsExec.exe \\<remote_machine> -u <username> -p <password> -d powershell -Command (New-Object Net.WebClient).DownloadFile('<url address','C:\file.exe')
But it doesn't work when I try this in a batch file:
(Set DownloadInstaller = "powershell -Command (New-Object Net.WebClient).DownloadFile('<url address','C:\file.exe')")
PsExec.exe \\<remote_machine> -u %username% -p %password% -h -d cmd /c %DownloadInstaller%