chkdsk
chkdsk

Reputation: 81

using cmd in powershell properly

at the moment i install a programm to a remote machine with batch. thats already working fine. but how can i use or "convert" the batch command below in powershell using the specific command for the prgramm to install it silent on the remote machine? this is my batch code.

set /p target=hostname 
echo.
copy /z "\\server1\tool.exe" "\\%target%\C$\temp"
echo.
PsExec.exe \\%target% cmd /c "\\%target%\C$\temp\tool.exe" /verysilent

Upvotes: 0

Views: 85

Answers (2)

chkdsk
chkdsk

Reputation: 81

Thanky guys for your answers. i did like that

$target = Read-Host "hostname"
Copy-Item -Path "\\server1\tool.exe" -Destination "\\$target\C$\temp"
PsExec.exe \\$target -s winrm.cmd quickconfig -q
Invoke-Command -ComputerName $target -ScriptBlock {
cmd /c "C:\temp\tool.exe" /verysilent
}

Upvotes: 0

Shaqil Ismail
Shaqil Ismail

Reputation: 1951

$target=hostname
Copy-Item -Path "\\server1\tool.exe" -Destination "\\$target\C$\temp"
Invoke-Command -ScriptBlock \\%target%\C$\temp\tool.exe -ComputerName $target -credential (USERNAME)

for the Invoke-Command -Scriptblock is the command you want to run, -ComputerName is the computer you want to start a process on, -Credential is the username to use to run the command. You will automatically be prompted to enter your password.

Upvotes: 1

Related Questions