Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify snapin before add?

I am getting following compilation issue in Powershell.

Add-PSSnapin : Cannot add Windows PowerShell snap-in VMware.VimAutomation.Core because it is already added. Verify the name of the snap-in and try again.

The error clearly mentions that I need to verify the name of the snap-in. It was added successfully when i execute first time itself.

How to verify snap-in exist ,if not then add?

like image 579
Samselvaprabu Avatar asked Mar 15 '12 14:03

Samselvaprabu


1 Answers

You can load it if it's not loaded already:

if(-not (Get-PSSnapin VMware.VimAutomation.Core))
{
   Add-PSSnapin VMware.VimAutomation.Core
}

You could also load it anyway and ignore the error:

Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
like image 180
Shay Levy Avatar answered Sep 20 '22 18:09

Shay Levy