Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function Run-RemoteCMD {
  2.  
  3. param(
  4. [Parameter(Mandatory=$true,valuefrompipeline=$true)]
  5. [string]$compname)
  6. begin {
  7. $command = Read-Host " Enter command to run"
  8. [string]$cmd = "CMD.EXE /C " +$command
  9. }
  10. process {
  11. $newproc = Invoke-WmiMethod -class Win32_process -name Create -ArgumentList ($cmd) -ComputerName $compname
  12. if ($newproc.ReturnValue -eq 0 )
  13. { Write-Output " Command $($command) invoked Sucessfully on $($compname)" }
  14. }
  15. End{Write-Output "Script ...END"}
  16. }
  17.  
  18.  
  19. Run-RemoteCMD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement