Create Win32_Process

When I first started with powershell, I converted some functions from a VBscript template I used into powershell code. One of those functions used WMI to create a process on a remote machine and then return the process ID that was created. The function is included at the end of this post.

Last week I worked with a colleague who was using a slightly modified version of this function. It was working fine for most processes, but in one particular case the process was failing on the remote Windows 2003 machine with an out of memory exception. If someone logged into the remote box and ran the process locally it would work fine. The function doesn’t define anything special about memory limits, so I started looking into the win32_process to see if there were memory limits that could be configured. Fortunately I was able to find this article http://blogs.technet.com/b/askperf/archive/2008/09/16/memory-and-handle-quotas-in-the-wmi-provider-service.aspx that discusses this specific issue. We ended up chaing the MemoryPerHost value from 134217728 (128MB) to 1073741824 (1024MB) and the process was able to complete.

[cc lang=”powershell”]
Function Start-WmiProcess ($computer, $cmd) {
$scope = New-Object management.managementscope “\\$computer\root\cimv2”
$scope.Connect()
$mp = new-object management.managementpath “win32_process”
$ogo = new-object management.objectgetoptions
$proc = new-object management.managementclass $scope,$mp,$ogo
$procID = ($proc.Create($cmd)).ProcessID
return $procID
}
[/cc]

This entry was posted in Scripting. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.