PowerCLI60R1 .net Framework issue

PowerCLI60R1 introduces “.NET Framework 4.5 or 4.5.x” as a prerequisite.
Some scripts may be indirectly impacted by this change.

PowerCLI has been improved another time and the version 6.0 Release 1 brings a lot of new features.

This version brings also some minor issues unfortunately.
Luc Dekens has written and excellent post on how to fix some of them.
This post however is focused on an indirect issue associated to the .Net Framework.

PowerCLI60R1 introduces “.NET Framework 4.5 or 4.5.x” as a prerequisite as mentioned in the “Installation Prerequisites”
Compatibility Matrixes for vSphere PowerCLI 6.0 Release 1
Compatibility Matrixes for vSphere PowerCLI 5.8 Release 1
This change is significant, even if it less visible compared to the introduction of modules.

Test script with workflow:
The script below will be used to demonstrate the indirect issue associated to this change.

workflow MyTest6{
	param(
	[string]$vCenter,
	[string]$session,
	$AllChildDatastore,
	[Parameter(Mandatory=$true)]
	$matchPattern
	)
	foreach -parallel($ChildDatastore in $AllChildDatastore){
		$Result = InlineScript{
		#Remove the line below for PowerCLI60R1
		#Add-Pssnapin VMware*
		Connect-VIServer -Server $Using:vcenter -Session $Using:session  | Out-Null
		$DatastoreView = get-view -ID ($Using:ChildDatastore.type + "-" + $Using:ChildDatastore.value )
		
			$HostDatastoreBrowserSearchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
			$HostDatastoreBrowserSearchSpec.matchPattern = $Using:matchPattern
			$HostDatastoreBrowserSearchSpec.sortFoldersFirst = $true

				$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
				$fileQueryFlags.fileOwner = $True
				$fileQueryFlags.fileSize = $True
				$fileQueryFlags.fileType = $True
				$fileQueryFlags.modification = $True
			$HostDatastoreBrowserSearchSpec.details = $fileQueryFlags
			
			$DatastoreName = $DatastoreView.Name
			$DatastoreUrl = $DatastoreView.info.url
			$DatastoreBrowser = Get-view -id ($DatastoreView.Browser)
			$datastorePath = "[" + $DatastoreName + "]"
			#The line below is the one generating the error in some scenarios.
			$HostDatastoreBrowserSearchResults = $DatastoreBrowser.SearchDatastoreSubFolders($datastorePath,$HostDatastoreBrowserSearchSpec)
			$HostDatastoreBrowserSearchResults
			
		}
		$Result
	}
}

Connect-VIServer -Server "pri-vc01.ad.local" -User "administrator@vsphere.local" -Password "MyL@b0123"
$AllChildDatastore = (Get-View -ViewType StoragePod -Filter @{"name" = "clu-01"}).childEntity
$FInalResult = MyTest6 -vcenter $global:DefaultVIServer.Name -Session $global:DefaultVIServer.SessionSecret -AllChildDatastore $AllChildDatastore -matchPattern "*"
$FInalResult | select * | ogv
Disconnect-VIServer -Server "pri-vc01.ad.local" -confirm:$false

Tests:

Test1:
Fresh installation of 2012R2
Feature “.Net Framework 3.5”
Fresh installation PowerCLI 5.8 Release 1
Add the line “Add-Pssnapin VMware*” to the script
Result: The script is executing without any errors

Test2:
Fresh installation of 2012
Feature “.Net Framework 3.5”
Fresh installation PowerCLI 5.8 Release 1
Add the line “Add-Pssnapin VMware*” to the script
Result: The script is executing without any errors

Test3:
Fresh installation of 2012R2
Fresh installation PowerCLI 6.0 Release 1
Result: The script is executing without any errors

Test4:
Fresh installation of 2012
Fresh installation PowerCLI 6.0 Release 1
Result: Errors reported by the script

Analyse of test4 result:
A “Windows PowerShell has stopped working” error will be raised for each datastore in the datastore cluster.

The error message in the PowerCLI prompt is not really helping:
Microsoft.PowerShell.Utility\Write-Error : The background process reported an error with the following message: .

The error messages in the Windows Application event viewer are more relevant:
Error 19/08/2015 20:40:39 Application Error 1000 (100)

Faulting application name: powershell.exe, version: 6.2.9200.16384, time stamp: 0x50109b7e
Faulting module name: clr.dll, version: 4.0.30319.17929, time stamp: 0x4ffa59b1
Exception code: 0xc00000fd
Fault offset: 0x000000000000ba8b
Faulting process id: 0x5d0
Faulting application start time: 0x01d0dab6e3720c6f
Faulting application path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Report Id: 2b1fe5e9-46aa-11e5-93eb-005056bfb74c
Faulting package full name:
Faulting package-relative application ID:

So it seems to be related to the .net Framework

With the help of “How to: Determine Which .NET Framework Versions Are Installed” the .Net version has been extracted:
378389 which is “.NET Framework 4.5”

So what will happen if we update to Microsoft .NET Framework 4.5.1?

Note:The error is only raised if the following line is present in the script
$DatastoreBrowser.SearchDatastoreSubFolders($datastorePath,$HostDatastoreBrowserSearchSpec)

Test 5 with Microsoft .NET Framework 4.5.1
Fresh installation of 2012
Fresh installation PowerCLI 6.0 Release 1
Installation of Microsoft .NET Framework 4.5.1
Result: The script is executing without any errors

The .Net version has been extracted:
378758 which is “.NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2”

Conclusion:
vSphere PowerCLI 6.0 Release 1 is the first version to rely on .Net Framework 4.5 or above.
Consequently, errors in PowerCLI60R1 could be due to the underlying .Net Framework 4.5 installed in the OS.

Always check the PowerCLI support for the local operating system.
2012 is indeed not supported for PowerCLI60R1 and PowerCLI58R1.

What is the purpose of this script?
For this part alone nearly nothing.
A new post will follow in one month with the complete script.

Leave a Reply

Your email address will not be published.