Execute a command with Powershell using Win32_Process

Tags: powershell

$cmd=“xcopy c:1.txt c:temp1.txt /A”

$server=“.”

$user=“domainuserName”

$pass=“p@ssw0rd”

$process = [WMIClass]“\$serverROOTcimv2:Win32_Process”

#$process.psbase.Scope.Options.userName=$user

#$process.psbase.Scope.Options.Password=$pass

#$process.psbase.Scope.Options.Impersonation = [System.Management.ImpersonationLevel]::Impersonate

#$process.psbase.Scope.Options.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy

$process.Create($cmd)

# get process id and returnValue

$process.ProcessId

$process.ReturnValue

Add a Comment