When running Add-PSSnapin I get the above error. This only seems to happen if I attempt to add the snapin a second time, however when this happens none of the Power CLI commands are available then until the server is rebooted.
Add-PSSnapin : An item with the same key has already been added.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
+ Add-PSSnapin $SnapinName;
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-PSSnapin], ArgumentExcept
ion
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Co
mmands.AddPSSnapinCommand
Attempts to remove the snap in at this point fail with:
Remove-PSSnapin : No Windows PowerShell snap-ins matching the pattern
'VmWare.VimAutomation.Core' were found. Check the pattern and then try the
command again.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
+ Remove-PSSnapin $SnapinName;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (VmWare.VimAutomation.Core:Stri
ng) [Remove-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.R
emovePSSnapinCommand
I've already tried un-installing the dll and reinstalling it, that doesn't make any difference
$dllpath = "C:\Program Files (x86)\Vmware\Infrastructure\vSphere PowerCLI\VMWare.VimAutomation.VICore.Cmdlets.dll"
$SnapinName = "VmWare.VimAutomation.Core"
#get the path for instalutil
$path = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory();
#create an alise for installtuil
set-alias installutil (resolve-path (join-path $path "installutil.exe"));
#uninstall the snapin
installutil /u $dllpath;
installutil $dllpath;
I've tried unloading the appdomain and then adding the snapin with the same result:
$appdomain = [AppDomain]::CurrentDomain
$appdomain.Unload #| Out-Null
Add-PSSnapin "VMware.VimAutomation.Core"
$appdomain.Load
Simply skipping past the error is no good because subsequent commands can't be found:
Add-PSSnapin "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue
Get-VM $VirtualMachine
The term 'Get-VM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Any help resolving this would be greatly appreciated.
Thanks