Windows Server 2008 R2 SP1 WMF 5.1
..> Import-Module vmware.powercli
Import-Module : Exception calling "OnImportModule" with "2" argument(s): "The type initializer for
'VMware.VimAutomation.Storage.Interop.V1.Service.StorageServiceFactory' threw an exception."
At line:1 char:1
+ Import-Module VMWARE.powercli
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Module], MethodInvocationException
+ FullyQualifiedErrorId : TypeInitializationException,Microsoft.PowerShell.Commands.ImportModuleCommand
...> $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:\Users\TEMP.BOIGROUP> Get-Module -ListAvailable
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.1 Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script 3.4.0 Pester {Describe, Context, It, Should...}
Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
Script 2.0.0 PSReadline {Get-PSReadLineKeyHandler, Set-PSReadLineKeyHandler, Remov...
Script 12.1.0.... VMware.CloudServices {Connect-Vcs, Disconnect-Vcs, Get-VcsOrganizationRole, Get...
Script 7.0.0.1... VMware.DeployAutomation {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-D...
Script 7.0.0.1... VMware.ImageBuilder {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-Esx...
Manifest 12.1.0.... VMware.PowerCLI
Script 7.0.1.1... VMware.Vim
Script 12.1.0.... VMware.VimAutomation.Cis.Core {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Script 12.0.0.... VMware.VimAutomation.Cloud {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, G...
Script 12.1.0.... VMware.VimAutomation.Common {Get-Task, New-OAuthSecurityContext, Stop-Task, Wait-Task}
Script 12.1.0.... VMware.VimAutomation.Core {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAd...
Script 12.1.0.... VMware.VimAutomation.Hcx {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance...
Script 7.13.0.... VMware.VimAutomation.HorizonView {Connect-HVServer, Disconnect-HVServer}
Script 12.0.0.... VMware.VimAutomation.License Get-LicenseDataManager
Script 12.0.0.... VMware.VimAutomation.Nsxt {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtPolicy...
Script 12.1.0.... VMware.VimAutomation.Sdk {Get-ErrorReport, Get-InstallPath, Get-PSVersion}
Script 12.1.0.... VMware.VimAutomation.Security {Add-AttestationServiceInfo, Add-KeyProviderServiceInfo, A...
Script 12.1.0.... VMware.VimAutomation.Srm {Connect-SrmServer, Disconnect-SrmServer}
Script 12.1.0.... VMware.VimAutomation.Storage {Add-EntityDefaultKeyProvider, Add-KeyManagementServer, Ad...
Script 1.6.0.0 VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script 12.1.0.... VMware.VimAutomation.Vds {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, E...
Script 12.1.0.... VMware.VimAutomation.Vmc {Add-VmcSddcHost, Connect-Vmc, Disconnect-Vmc, Get-AwsAcco...
Script 12.0.0.... VMware.VimAutomation.vROps {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-O...
Script 12.1.0.... VMware.VimAutomation.WorkloadMan... {Disable-WMCluster, Enable-WMCluster, Get-WMCluster, Get-W...
Script 12.1.0.... VMware.VumAutomation {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Complia...
You tagged this with "offline install".
How did you create the package for the offline install?
Under which version of PowerShell did you create that package?
Under PSV5.1 modules are normally not installed in C:\Program Files\WindowsPowerShell\Modules
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Installation was attempted in 2 different ways producing much same results:
1. Extracting PowerCLI ZIP into the directory on a target machine (offline)
2. Installing on a "connected" machine and then copying contents of the Modules to target machine (offline)
PS C:\Users\***> $env:PSModulePath
\\***\homedrives\***\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\TEMP.BOIGROUP> $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
This is a Windows Server 2008 R2 with WMF 5.1 patch installed
1. I'm not a fan of that ZIP file.
What does $env:PSModulePath.Split(';') return on the target machine?
2. You didn't say which PS version you have on that "connected" machine.
If that is not the same as the target machine there will be issues.
Did you use the Save-Module cmdlet on the "connected" machine?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, misunderstood the question. So above post has the version of the target system.
Below is the version of the source system:
PS C:\Users\**> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.610
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.610
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\Users\**> $env:PSModulePath.Split(';')
\\**\homedrives\**\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules
I would definitely try to do the following
- make sure all PowerCLI files on the target machine are removed (also if there is something still under Programs and Features - old MSI install)
- on a connected machine, that runs the same PS version as the target machine, use the Save-Module comdlet
- transfer the saved files to the correct folders on the target machine
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Will try that, although getting exact same version would be a challenge ![]()
Old server it is and on a client side...
In theory, it is only the PowerShell versions that should match.
You can follow the "offline" steps in Welcome PowerCLI to the PowerShell Gallery – Install Process Updates and Updating PowerCLI through the PowerShell Gallery
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I had the same error. Ended up having an old MSI install that I missed. After uninstall of the MSI install the new 12.x modules worked fine.
Thought I'd post here also in case it helped anyone;
I had a need to configure PowerCLI on one of our VMs running Windows Server 2016 (because I left my laptop at work lol and it was Patching weekend, and PowerCLI is immensely handy when it comes to snapshot management).
In my case, the install-module vmware.powercli went through fine, but it was the import of the module (ipmo vmware.powercli) that failed with OP's error.
My fix was to make sure Program Files\Powershell folder was unset from "Read Only" as much as possible (wasn't able to set it for some folders so chose an "Ignore all" for those).
It was then able to import the module fine, so I guess it was just failing the import because certain parts were set to Read-Only. Hope this helps others!
