5 Replies Latest reply on Nov 2, 2018 1:28 PM by fcocquyt16

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

    ym2018 Novice

      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

        • 1. Re:  'VMWare.VimAutomation.Core' is not installed on this computer
          LeighdePaor Lurker

          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

          • 2. Re:  'VMWare.VimAutomation.Core' is not installed on this computer
            LucD Guru
            Community WarriorsUser ModeratorsvExpert

            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.

            • 3. Re:  'VMWare.VimAutomation.Core' is not installed on this computer
              ym2018 Novice
              Thanks! I've removed Add-PSSnapin lines from the script and it worked.
              • 4. Re:  'VMWare.VimAutomation.Core' is not installed on this computer
                vikashvicky675 Lurker

                Remove that line with lines below and it will work.

                 

                Import-Module VMware.VimAutomation.Core

                connect-VIServer $vcserver

                 

                my 2 cents

                • 5. Re:  'VMWare.VimAutomation.Core' is not installed on this computer
                  fcocquyt16 Novice

                  Import-Module VMware.VimAutomation.Core

                   

                  worked for me - thanks!