Notes of a scripter

Issues with PowerShell Modules and Duplicate Cmdlets

At the end of the day I always take my laptop with me as I never know when I’ll get a call about server issues.  So my PowerShell sessions remain open all of the time, with all of the modules loaded.  Granted I do save my scripts that I work on frequently, and I had a problem before losing a few scripts without having a recent save.  So I got a surprised with the results from a cmdlet that I used frequently didn’t have the desired information.

Get-Cluster Error
Get-Cluster Error

I was trying to get the datastores for a VM Cluster so we can make some modifications to them.  When I got this error message (image above), I was just in shock, and this is just not making any sense to me.  How could this not return the typical results.  So I double check the spelling as stated in the error.  I make sure that I’m connected to the vCenter, and the PowerCLI module is loaded.  Once I ran the command to check the loaded modules, only then did i see the issue.

Get-Modules Results

So as seen in the image above, I can see that I have the required PowerCLI modules loaded, but I also have the FailoverClusters module loaded as well.  So I then pulled the list of commands from the FailoverCluster module.

Commands for FailoverClusters Modules

The FailoverClusters module has the command, Get-Cluster, that is also in the PowerCLI module.  So when I used the command, Get-Cluster, I expected to see information about the VMware Cluster, but instead I got the error about misspelling of the cluster name.

Resolution to the issue

This was a simple fix once I was able to find the issue.  Simply unload the module that I was no longer using.

 Remove-Module -Name failoverclusters 

I even tried to reload the VMware module and it still didn’t recognizanced the VMware cmdlet, only the failover cluster one.  So if loading modules for a single time use, make sure to unload or restart the PowerShell session afterwards to prevent unnecessary issues.

-Stuart

Exit mobile version