How to check if PowerCLI libraries are loaded in PowerShell/PowerGUI
If you write scripts in PowerShell or PowerGUI, it might be handy to check if the PowerCLI libraries are loaded.
Even though you have PowerCLI installed, this does not mean the objects are loaded in your PowerShell session.
In PowerGUI for example, you can check this by clicking File – PowerShell Libraries.
I have PowerCLI installed, but the libraries are not loaded. So running a PowerCLI cmdlet will result in an error.
Use the following code to check if the PowerCLI objects are loaded in PowerGUI. If not, you can display an error, load the objects, …
Try
{
Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction Stop
}
Catch
{
Write-Error "PowerCLI Library is not loaded in PowerGUI. Go to ""File - PowerShell Libraries"" and enable ""VMware.VimAutomation.Core""."
}
Categories: PowerCLI, PowerShell, VMware, vSphere