HewlettPackard / POSH-HPEOneView

PowerShell language bindings library for HPE OneView.
http://hewlettpackard.github.io/POSH-HPEOneView/
126 stars 52 forks source link

Release 5.0.2152.1665 fails to load on systems with .NetFramework 4.7.1 or older #414

Closed ChrisLynchHPE closed 4 years ago

ChrisLynchHPE commented 5 years ago

On certain systems, like Windows Server 2012 R2, where Windows Management Framework 5.1 is installed, the library will fail to load with NewObject : Cannot find type [HPOneview.Library.Version] exception.

The library is failing to load because the .NetFramework client is not at required minimum 4.7.2 release. Currently, the PSD1 has the DotNetFrameworkVersion and CLRVersion set. PowerShell appears to ignore the DotNetFrameworkVersion property, thus allowing the module to continue loading, but the DLL class library fails to load without any warning or indication.

The PSM1 needs a method to identify if the system meets the minimum requirement for PowerShell 5.1. The following code will be added:

if ($PSVersionTable.PSVersion -match '5.1')
{

    $ReleaseKey = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' |  Get-ItemPropertyValue -Name Release

    if ($ReleaseKey -lt 461808)
    {
        [System.String]$Exception                                  = 'InvalidOperationException'
        [System.String]$ErrorId                                    = 'UnableToLoadModuleMissingDependancy'
        [System.Object]$TargetObject                               = 'Import-Module HPOneView.500'
        [System.Management.Automation.ErrorCategory]$ErrorCategory = 'ResourceUnavailable'
        [System.String]$Message                                    = 'The library is unable to load due to this sytem missing the required .NetFramework 4.7.2 client.  Please visit https://go.microsoft.com/fwlink/?LinkId=863265 to download the .NetFramework 4.7.2 Offline Installer.'

        throw [Management.Automation.ErrorRecord]::new((New-Object $Exception $Message), $ErrorID, $ErrorCategory, $TargetObject)

    }   

}
ChrisLynchHPE commented 4 years ago

This is fixed in Release 5.0.2226.2609 and in PowerShell Gallery.

sbkurid commented 4 years ago

this issue is still persist.

PS C:\Windows\system32> Import-Module HPOneView.500
Import-Module : The library is unable to load due to this sytem missing the required .NetFramework 4.7.2 client.  Please visit https://go.microsoft.com/fwlink/?LinkId=863265 to download the .NetFramework 4.7.2 Offline Installer.
At line:1 char:1
+ Import-Module HPOneView.500
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Import-Module HPOneView.500:String) [Import-Module], InvalidOperationException
    + FullyQualifiedErrorId : UnableToLoadModuleMissingDependancy,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\Windows\system32> Get-Module -ListAvailable HPOne*

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.0.240... HPOneView.500                       {Install-HPOVLogicalInterconnectFirmware, Get-HPOVOSDeploymentPlanAttribute, Remove-HPOVScope, Get-HPOVApplianceAvailableSecurityMode...}

PS C:\Windows\system32> Get-Module -ListAvailable HPOne* | fl

Name              : HPOneView.500
Path              : C:\Program Files\WindowsPowerShell\Modules\HPOneView.500\5.0.2400.1845\HPOneView.500.psd1
Description       : HPE OneView PowerShell Library
ModuleType        : Script
Version           : 5.0.2400.1845
NestedModules     : {}
ExportedFunctions : {Install-HPOVLogicalInterconnectFirmware, Get-HPOVOSDeploymentPlanAttribute, Remove-HPOVScope, Get-HPOVApplianceAvailableSecurityMode...}
ExportedCmdlets   :
ExportedVariables :
ExportedAliases   : {New-HPOVAddressRange, Get-HPOVProfileConnectionList, New-HPOVSanManager, New-HPOVLdap...}

PS C:\Windows\system32>
ChrisLynchHPE commented 4 years ago

Please provide the output of $PSVersionTable from this system.

ChrisLynchHPE commented 4 years ago

I just tried to replicate this on a new Windows 2012 R2 system with Windows Management Framework 5.1 installed, and was unable to. So, unless you can provide the $PSVersionTable and even Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release, this issue will remain closed, as the issue is specific to your system.

motonuke commented 3 years ago

Hello, i've experienced a similar issue as above, but my use case is probably more of a fringe case than anything. I wanted to post this for others to reference.

I was getting the "library unable to load due to Net Framework 4.7.2 or higher not being installed (paraphrasing)" error upon trying to do an import-module HPOneView.500. However, what I didn't account for was that this system has the Japanese Lang pack installed. I did have Net Framework 4.8 installed. However, I didn't realize a Net Framework Japanese Lang pack needed to be installed (1033 was at an acceptable version, 1041 was below).

PS C:\classfiles\PS_Scripts> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1005
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1005
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\classfiles\PS_Scripts> Get-Module -ListAvailable HPOne* | select name,version

Name          Version
----          -------
HPOneView.500 5.0.2226.2609

Other hints from the internet have you run the command Get-Item 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release. This returns only the first version (or English based version? Not sure) it finds (Maybe it does this because 1033, aka English, is found before 1041, aka Japanese?).

PS C:\classfiles\PS_Scripts> Get-Item 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release
528049

Reading this thread, I see your code uses a more appropriate error handling command Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release. When running this manually, it returns all values and this was how I discovered 2 versions where being detected.

PS C:\classfiles\PS_Scripts> Get-childItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\' | Get-ItemPropertyValue -Name Release
528049
394802

Installing the Net Framework 4.8 Japanese Lang Pack fixed this right up and allowed the module to import without errors.

Hope this helps someone else out there!

Cheers!