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.


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
}
Posted in Scripting | Leave a comment

Using vSphere Image Builder and Powerpath/VE

I typically use vSphere Image Builder to create custom ISO images that contain EMC PowerPath VE. The problem is, I need to add three packages in the correct order — and I never can remember the correct order. A few tries and I usually have what I need. I thought it would be worthwhile to write these down, so at the very least I could find the correct order in the future.

The code below assumes you have the ESXi500-201206001.zip and EMCPower.VMWARE.5.7.P01.b002.zip folders already downloaded and stored in your current working directory.


$buildName = "VM50-721882_ppve57p1"

Add-EsxSoftwareDepot –DepotUrl ESXi500-201206001.zip
$standard = Get-EsxImageProfile | ?{$_.Name -match 'standard'}
$newProfile = New-EsxImageProfile -CloneProfile $standard.name -Name $buildName

# Add powerpath VE to the image
Add-EsxSoftwareDepot -DepotUrl EMCPower.VMWARE.5.7.P01.b002.zip
"powerpath.lib.esx","powerpath.cim.esx","powerpath.plugin.esx" | %{ Add-EsxSoftwarePackage -ImageProfile $newProfile -SoftwarePackage $_ }

# Export Image in ISO and ZIP format
Export-EsxImageProfile –ImageProfile $newProfile -FilePath "$buildName.iso" -ExportToIso
Export-EsxImageProfile –ImageProfile $newProfile -FilePath "Bundle_$buildName.zip" -ExportToBundle
Posted in Scripting, Virtualization | Leave a comment

VMworld 2012 – Powershell dinner

My favorite part of VMworld is the people you meet. Last week I was lucky enough to meet up with many powershell/PowerCLI experts and have some awesome discussions.


I wasn’t able to get everyones name/card, but I believe the first person in that picture is from Cisco, followed by Matt Boren (@mtboren), Eric Williams (@aeroic78), Dimitar Hristov, Alan Renouf (@alanrenouf), Hal Rottenberg (@halr9000), Luc Dekens (@LucD22), Josh Atwell (@Josh_Atwell), Brian Wuchner (@bwuch), Jonathan Medd (@jonathanmedd), Allen Crawford (@allen_crawford) and Clinton Kitson (@clintonskitson)

Posted in Scripting, Virtualization | 1 Comment

Powershell – Measure Historical Command

Have you ever been working in a Powershell console and have a command run longer than expected? Did you wish that you had wrapped that command in a Measure-Command so that you could view execution time? This has happened to me several times, so recently I started working on a Measure-HistoricalCommand function that would use Get-History to create a New-TimeSpan from the StartExecutionTime and EndExecutionTime properties. I would like to say thanks to @mtboren from vnugglets.com who helped add some functionality and speed up this function.


Function Measure-HistoricalCommand {
	param(
		## for getting info about the last X commands
		[parameter(Mandatory=$false,ParameterSetName="ByCommandCount")][alias("Count")][Int]$Last=1,
		## for getting info about a specific command ID
		[parameter(Mandatory=$true,ParameterSetName="ByCommandId")][alias("Id")][Int]$CommandID
	) ## end param

	process {
		## create the Get-History command expression to invoke; use -Id or -Count based on the params passed to this function
		$strGetHistoryExpr = "Get-History " + $(if ($CommandID) {"-Id $CommandID"} else {"-Count $Last"})
		Invoke-Expression $strGetHistoryExpr | %{
			$ts = New-TimeSpan -Start $_.StartExecutionTime -End $_.EndExecutionTime
			## again, take out the array, just return the object straight away
			#$myResults += New-Object PSObject -Property @{
			New-Object -TypeName PSObject -Property @{
				ID = $_.ID
				CommandLine = $_.CommandLIne
				EndExectuionTime = $_.EndExecutionTime
				StartExecutionTime = $_.StartExecutionTime
				TimeSpan = $ts
				TotalSec = $ts.TotalSeconds
			} ## end new-psobject
		} ## end History foreach-object
	} ## end process
} ## end fn
Posted in Scripting | Leave a comment

VMware SRM and SSL certificates

I recently ran into some problems with SRM and SSL certificates. My lab for this project has two vcenters — both using CA signed SSL certificates. During the SRM install I used the automatically generated certificates. When the installations were complete, I was unable to pair the sites. The error message I received was SSL related:

The host certificate chain is not complete. reason.msg

I spent a lot of time trying to figure out the ‘trick’ on how to create certificates that SRM would actually use. I finally found a blog post here: http://thephuck.com/virtualization/creating-certificates-for-vmware-srm-or-vcenter-using-openssl-made-easy-with-video/ that pointed me in the right direction. I followed the instructions but SRM still wouldn’t use the certificate.

Looking at the certificate created, I noticed a couple of things were missing. Specifically, the following two settings that actually make the SRM certificate different:

extendedKeyUsage = serverAuth, clientAuth
subjectAltName = DNS: fqdn.of.srm.server

Even though my CSR contained both of these settings, the CA did not include them in the certificate. I decided to make a copy of the ‘Web Server’ certificate template I normally use and add a ‘Client Authentication’ purpose. However, when I got to my CA, I noticed an SCCM Web Server template that already had the options I needed.

I followed the instructions, but made two different changes when submitting the CSR to my CA:

Certificate Template: SCCM Web Server (which has a Server & Client purpose)
Attributes: san:dns=host.name.of.vcenter (which adds the subject alternative names)

Finally, after what felt like weeks of SSL hell, I was able to pair my sites. Many thanks to Luke @ThepHuck for these valuable instructions.

Posted in Virtualization | 6 Comments