0
votes

I am trying to execute a powershell script from the host 1.2.3.3 on the box 1.2.3.4 remotely

$cred = get-credential 
$process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __Class = 'Win32_Process'" -namespace "root\cimv2" -computername 1.2.3.4 -credential $cred 
$results = $process.Create("powershell.exe /c C:\Windows\temp\hello.ps1 arg1") 

I can see the process getting created (as the return value says 0) but the process is dies down immediately in the remote system(1.2.3.4)

I tried powershell.exe -file option also instead of powershell.exe /c

I tried using Invoke-Command but that dosent work because of trusted hosts issue. Can somebody shed some light on this?

1

1 Answers

0
votes

PowerShell.exe parameters starts with a dash (e.g '-'), for full help type: PowerShell.exe /?.

What do you expect to happen? What the script is doing? Should it "die" this way?