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

Advertisements
  1. April 3, 2013 at 23:47

    How do I get to enable VMware.vimAutomation.core. Where is the library. I imported it over at powercliGUI but when I do get-module and get-module -list I don’t see VMware.vimAutomation.core. I will be glad if you can point to the right direction.

    • April 14, 2013 at 19:33

      Did you install PowerCLI from VMware on your machine?

  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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: