Psexec doesnt execute .bat

100 views Asked by At

Ive been looking in other posts and i dont know why this script isnt working, ive been looking for syntax error.The script copies the .bat file fine in C: ,the .bat works locally, but remotely doesnt get executed (i have tried with various domain users, local admin of the pcs). And PSEXEC gives me no error (ERROR 0) help appreciated.

$usuario = 'ADMIN'
$password = 'XXXX'


$rutaLog = "D:\SCRIPTSM\ALV\DESPM\fallos.log"
$fecha = (Get-Date).ToString('dd.MM.yyyy "y en esta hora" HH:mm:ss')
$prumod = 'D:\SCRIPTSM\ALV\DESPM'

$equipos = Get-Content D:\SCRIPTSM\despliegueFi\equipos.txt

foreach ($equipo in $equipos){
    if (test-connection -ComputerName $equipo -Count 1 -Quiet){

         Copy-Item -Path $prumod\prueba.bat \\$equipo\c$
         Set-Location -Path "D:\SCRIPTSM\PSTools"
         .\psexec.exe \\$equipo -u $usuario -p $password -h "C:\prueba.bat"
         Set-Location -Path $prumod
   
    }else{
         Set-Location -Path $prumod
         Write-Output "Equipo apagado/no se accede en esta fecha $fecha --> $equipo" >> $rutaLog
    }
}

The exit of the command, and the file gets copied on the remote pc.The .bat is trying to change registry keys.

Sysinternals - www.sysinternals.com

La operaci¢n se complet¢ correctamente.

La operaci¢n se complet¢ correctamente.

.\psexec.exe : Connecting to X.X.X.X...
En D:\SCRIPTSM\ALV\DESPM\MODU2.ps1: 20 Carácter: 10
+          .\psexec.exe \\$equipo -u $usuario -p $password -h "C:\prueb ...
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Connecting to X.X.X.X...:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Starting PSEXESVC service on X.X.X.X...
Connecting with PsExec service on X.X.X.X...
Starting C:\prueba.bat on X.X.X.X...
C:\prueba.bat exited on X.X.X.X with error code 0.
0

There are 0 answers