MathieuBuisson / Powershell-VMware

Powershell or PowerCLI modules for VMware administration/troubleshooting tasks
71 stars 31 forks source link

Add-PSSnapin VMware.VimAutomation.Core #2

Closed Vulp-OS closed 9 years ago

Vulp-OS commented 9 years ago

On line 102 of Get-StoreageViewsReport, you run this if statement: If(-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) { Add-PSSnapin VMware.VimAutomation.Core }

For some reason, at least on machines in my environment, this snapin doesn't show as loaded, but when attempting to load it, an error is reported, stating that "an item with the same key has already been added."

The snapins that are loaded for me are Microsoft.PowerShell.Core VMware.VimAutomation.License VMware.DeployAutomation VMware.ImageBuilder

MathieuBuisson commented 9 years ago

You are probably using PowerCLI 6.0. Could you send me the output of the command : Get-PowerCLIVersion , please ?

As mentioned in the following link, in PowerCLI 6.0, VMware.VimAutomation.Core is both a module and a snap-in : https://www.vmware.com/support/developer/PowerCLI/PowerCLI60R1/powercli60r1-releasenotes.html

So, I will need to check for the PowerCLI version first, and then, use Get-Module and Import-Module (instead of Get-PSSnapin and Add-PSSnapin) if it is PowerCLI 6.0.

I will work on that next week.

Vulp-OS commented 9 years ago

You are correct in assuming that I am using PowerCLI 6.0.

Here's the requested information:

PowerCLI Version

VMware vSphere PowerCLI 6.0 Release 1 build 2548067

Component Versions

VMWare AutoDeploy PowerCLI Component 6.0 build 2358282 VMWare ImageBuilder PowerCLI Component 6.0 build 2358282 VMware License PowerCLI Component 6.0 build 2315846 VMware vSphere PowerCLI Component 6.0 build 2548068 VMware Cloud Infrastructure Suite PowerCLI Component 6.0 build 2548068 VMware HA PowerCLI Component 6.0 build 2510422 VMware PowerCLI Component for Storage Management 6.0 build 2522368 VMware VDS PowerCLI Component 6.0 build 2548068

Please excuse the formatting that occurs. GitHub assumes that things with dashes below them are headings.

MathieuBuisson commented 9 years ago

Thank you. I'm going to fix this next week, normally.

MathieuBuisson commented 9 years ago

I added the check for PowerCLI 6.x by checking if the module VMware.VimAutomation.Core is available and then, I use Import-Module if it is not already loaded. Now, I check the snap-in only if the module is not available ( for older versions of PowerCLI ).

Could you confirm it fixed the issue you encountered, please ? Thanks

Vulp-OS commented 9 years ago

This appears to have corrected the issue. I receive no more errors when running this module.