Home > PowerCLI, PowerShell, VMware, vSphere > How to check if PowerCLI libraries are loaded in PowerShell/PowerGUI

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.

image

I have PowerCLI installed, but the libraries are not loaded.  So running a PowerCLI cmdlet will result in an error.

image

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""."
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers