Using Powershell 1.0 to execute remote processes that need PacketPrivacy authentication

I was using Powershell to do some work remotely with a DCOM component and ran into a requirement to use PacketPrivacy AuthenticationLevel.    I’ve found sometimes having commands to copy files from a unc path to a remote machine, then executing them is the most effective.  This technique introduces a bit of latency since the files have to be put locally, but in some cases, this is a necessary.  PS – This is for powershell 1.0.


#Loop Through a computer list
$ComputerList = Get-Content(“serverlist.txt”)

foreach($server in $ComputerList)
{
 Write-Host $server
 #trap [Exception] {continue}

#Set the command to execute remotely
 $cmd=”cmd /C PathtoFileOrEXE”

#Set the username and password.  You could also look at using PS Credential
 $user=”domainNameusername”
 $pass=”xxxx”

#Make sure to set the object before setting the options. 🙂
 $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

#Launch the command
 $process.Create($cmd)


 #Get process id and returnValue
 $process.ProcessId
 $process.ReturnValue
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: