VMware Cloud Community
ym2018
Contributor
Contributor

'VMWare.VimAutomation.Core' is not installed on this computer

Hi,

I'm new in PowerCLI world and I need some help.

I'm getting the following error:

Add-PSSnapin : The Windows PowerShell snap-in 'VMWare.VimAutomation.Core' is not installed on this computer.

 

Usefull information from my computer:

PowerCLI Version:

----------------

   VMware PowerCLI 10.0.0 build 7895300

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component PowerCLI Component 10.0 build 7893915

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 10.0 build 7893909

 

$PSVersionTable:

Name                           Value

----                           -----

PSVersion                      5.1.16299.251

PSEdition                      Desktop

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

BuildVersion                   10.0.16299.251

CLRVersion                     4.0.30319.42000

WSManStackVersion              3.0

PSRemotingProtocolVersion      2.3

SerializationVersion           1.1.0.1

Reply
0 Kudos
6 Replies
LeighdePaor
Contributor
Contributor

With PowerShell version 5 you use:

Import-Module -Name VMware.PowerCLI

If it's installed then that will allow you to use it.

I use a function which checks the PowerShell version and if it's installed or not see below:

It supports -Verbose common parameter and returns true or false depending on the result so it can be used from PowerShell scripts, it also exits with error codes 0 (no error) or 1 (error state) so it can be evaluated from dos batch files etc.

function Enable-PowerCLI ()

{

    Write-Verbose ("Entered function : {0} " -f $MyInvocation.MyCommand)

    $ModuleName = "VMware.PowerCLI"

    if(($PSVersionTable.PSVersion.Major -ge 5) -and ($PSVersionTable.PSEdition -ne "Core"))

    { 

        Write-Verbose "PowerShell version greater/equal to 5 installed" 

        if (Get-Module -Name $ModuleName){Write-Verbose "PowerShell $ModuleName Module already loaded"; return $True}

        else

        {

   

            if (!(Get-Module -Name $ModuleName) -and (Get-Module -ListAvailable -Name $ModuleName))

            {

                try

                {

                    Write-Verbose "loading the PowerShell $ModuleName Module..." 

                    Import-Module -Name $ModuleName -ErrorAction Stop

                    Write-Verbose ("Exiting function : {0} " -f $MyInvocation.MyCommand)

                }

                catch # Try to install if loading fails

                {

                    Write-Host "Failed initial loading of PowerShell $ModuleName Module..." 

                    Try

                    {

                        Write-Verbose "Checking/Installing NuGet package provider" 

                        if(!(Get-PackageProvider -ListAvailable -Name "NuGet")){Get-PackageProvider -Name NuGet -Force}

                        Write-Verbose "Setting PowerShell Gallery as trusted Repository" 

                        Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

                        Write-Verbose "Installing and loading the PowerShell $ModuleName Module..." 

                        Install-Module $ModuleName -scope CurrentUser -Force -ErrorAction Stop

                        Import-Module -Name $ModuleName -ErrorAction Stop

                    }

                    catch{Write-Host "ERROR: Cannot load or install the VMware PowerCLI Module. Please install manually." - ForegroundColor Red;return $false;exit 1}

                }

                Write-Verbose ("Exiting function : {0} " -f $MyInvocation.MyCommand)

                return $True

            } # End if (!(Get-Module -Name "VMware.PowerCLI") -and (Get-Module -ListAvailable -Name "VMware.PowerCLI"))

        }

    } # End if(($PSVersionTable.PSVersion.Major -ge 5) -and ($PSVersionTable.PSEdition -ne "Core"))

    elseif(($PSVersionTable.PSVersion.Major -ge 3)-and ($PSVersionTable.PSVersion.Major -lt 5))

    {

        Write-Verbose "PowerShell version greater/equal to 3 but less than 5 installed" 

        $ModuleList = @(

            "VMware.VimAutomation.Core",

            "VMware.VimAutomation.Vds",

            "VMware.VimAutomation.Cloud",

            "VMware.VimAutomation.PCloud",

            "VMware.VimAutomation.Storage",

            "VMware.VimAutomation.HA",

            "VMware.VimAutomation.vROps",

            "VMware.VumAutomation",

            "VMware.VimAutomation.License",

            "VMware.VimAutomation.Cis.Core"

            )

           

        foreach($Module in $ModuleList)

        {

            if ((!(Get-Module -Name $Module)) -and (Get-Module -ListAvailable -Name $Module))

            { 

                Write-Verbose "loading the $Module Module..." 

                try

                {

                    Import-Module -Name $Module -ErrorAction Stop

                    $Loaded = $True 

                }

                catch {Write-Host "ERROR: Cannot load the $Module Module. Is VMware PowerCLI installed?" - ForegroundColor Red;return $false;exit 1} # Error out if loading fails

            } # End if ((!(Get-Module -Name $Module)) -and (Get-Module -ListAvailable -Name $Module)) 

            elseif ((!(Get-PSSnapin -Name $Module -ErrorAction SilentlyContinue)) -and (!(Get-Module -Name $Module)) -and ($Loaded -ne $True))

            { 

                Write-Verbose "loading the $Module Snapin..." 

                Try {Add-PSSnapin -PassThru $Module -ErrorAction Stop}

                catch {Write-Host "ERROR: Cannot load the $Module Snapin or Module. Is VMware PowerCLI installed?" - ForegroundColor Red;return $false;exit 1} # Error out if loading fails

            }

        } # End foreach($Module in $ModuleList)

        Write-Verbose ("Exiting function : {0} " -f $MyInvocation.MyCommand)

        return $True

    }

    else{Write-Host "PowerShell version less than 3 installed!" - ForegroundColor Red;return $false;exit 1 }

    Write-Verbose ("Exiting function : {0} " -f $MyInvocation.MyCommand)

} # End function Enable-PowerCLI

Reply
0 Kudos
LucD
Leadership
Leadership

If you are on PowerCLI 10, there are no PSSnapin anymore.

If you still have scripts that contain Add-PSSnapin lines, remove those lines from the script.

If you are on PowerShell 3, or higher, you don't have to explicitly import modules anymore, if these modules are installed in one of the folders listed in $env:PSModulePath.

The first time you use a PowerCLI cmdlet, the required module will be loaded thanks to PowerShell module auto-load feature.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ym2018
Contributor
Contributor

Thanks! I've removed Add-PSSnapin lines from the script and it worked.
Reply
0 Kudos
vikashvicky675
Contributor
Contributor

Remove that line with lines below and it will work.

Import-Module VMware.VimAutomation.Core

connect-VIServer $vcserver

my 2 cents Smiley Wink

Reply
0 Kudos
fcocquyt16
Contributor
Contributor

Import-Module VMware.VimAutomation.Core

 

worked for me - thanks!

Reply
0 Kudos
ghardt
Contributor
Contributor

If you don't have VMWare.VIMAutomation.Core installed, you can do that from within PowerShell:

Install-Module -Name VMware.VimAutomation.Core

or you can download and install all of the PowerCLI tools:

VMware PowerCLI

Other statements in this thread are accurate: you likely don't need to use the Add-PSSnapin line anymore. You can replace it with:

Import-Module VMware.VimAutomation.Core

or allow PowerShell to auto-load it. (I prefer to explicitly load modules as it adds to the in-code documentation.)

gH