Created
March 13, 2015 17:05
-
-
Save adamedx/e548a0df4e46d5a2dbd8 to your computer and use it in GitHub Desktop.
Job object in Windows example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ($args.length -gt 0) | |
{ | |
$mypid = $args[0] | |
} | |
else | |
{ | |
$mypid = $pid | |
} | |
$myproc = get-wmiobject -Class win32_process -filter "ProcessId=$mypid" | |
$mypath = $myproc.__PATH | |
$mypath | |
$myfixedpath=$mypath.replace("\","\\") | |
$myfixedpath2=$myfixedpath | |
$myfixedpath=$myfixedpath.replace("""","""""") | |
$myfixedpath | |
$mypathquery="__PATH='" + $myfixedpath + "'" | |
$mypathquery | |
$myfun=gwmi Win32_Process -filter "$mypathquery" | |
$myfun | |
$mymemberquery="Member='" + $myfixedpath2 + "'" | |
$mymemberquery | |
$myjobproc=gwmi Win32_NamedJobObjectProcess -filter $mymemberquery | |
$myjobproc | |
$mycol=$myjobproc.Collection.split("=")[1].trim("""") | |
$mycol | |
$mysettingQuery = "SettingId='" + $mycol + "'" | |
$mysettingQuery | |
$myLimits=gwmi Win32_NamedJobObjectLimitSetting -Filter "$mysettingQuery" | |
$myValue = $myLimits.ProcessMemoryLimit | |
# In Win2k8R2, the wsman: settings are inaccessible when running under winrm | |
#$myDesired=get-item WSMan:\localhost\Shell\MaxMemoryPerShellMB | |
# Use registry to work around since this is where the settings are actually stored: | |
$wsmankey=get-item -path HKLM:\software\Microsoft\Windows\CurrentVersion\WSMAN\Client | |
$myDesired=$wsmankey.GetValue("MaxMemoryPerShellMB") | |
# $myDesiredMb=[int]$mydesired.Value * 1024 * 1024 | |
$myDesiredMb=[int]$mydesired * 1024 * 1024 | |
$mydesiredMb | |
$myValue | |
if ( $myValue -ne $myDesiredMb ) | |
{ | |
$errorValue="Value is '" + $myValue + "', should be " + "'" + $myDesiredMb + "'" | |
write-Error $errorValue | |
} | |
else | |
{ | |
$outputValue = "Expected value of " + $myValue + " bytes found for the job object associated with this process" | |
write-host -foregroundcolor green $outputValue | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment