PowerCLI

 View Only
Expand all | Collapse all

Trouble installing PowerCLI on Windows server

  • 1.  Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 11:24 AM

    Hello,

    I've ran this:

     

    Save-Module -Name VMware.PowerCLI -Path E:\PowerCli\

     

    I can see all the folders downloaded.

    However if I run any VMware related commands it can't find them:

     

    Get-Cluster : The term 'Get-Cluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try 
    again.

     

    What am I doing wrong here?

    Thanks



  • 2.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 11:40 AM

    After the Save-Module, you have to copy the folders to a directory that is listed in $env:PSModulePath.
    See PowerCLI Offline Installation Walkthrough for a more detailed description of the procedure.



  • 3.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 12:14 PM

    Thanks I was using that.  If I use $env:PSModulePath then I see many paths, but I see the folders where I copied too.

    C:\Program Files\WindowsPowerShell\Modules;

    d-----        2/17/2022  11:26 AM                VMware.CloudServices
    d-----        2/17/2022  11:26 AM                VMware.DeployAutomation
    d-----        2/17/2022  11:26 AM                VMware.ImageBuilder
    d-----        2/17/2022  11:26 AM                VMware.PowerCLI
    d-----        2/17/2022  11:25 AM                VMware.PowerCLI.Sdk
    d-----        2/17/2022  11:25 AM                VMware.PowerCLI.Sdk.Types
    d-----        2/17/2022  11:25 AM                VMware.PowerCLI.VCenter
    d-----        2/17/2022  11:25 AM                VMware.PowerCLI.VCenter.Types.ApplianceService
    d-----        2/17/2022  11:25 AM                VMware.PowerCLI.VCenter.Types.CertificateManagement
    d-----        2/17/2022  11:25 AM                VMware.Sdk.Runtime
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.Access
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.Health
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.InfraProfile
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.LocalAccounts
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.Logging
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.Networking
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.Recovery
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.SupportBundle
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.System
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Appliance.Update
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Cis
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Cis.Tagging
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Content
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.ContentLibrary
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Esx.Hcl
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Esx.Hosts
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.Esx.Settings
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.VAPI.Metadata
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Authentication
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.CertManagement
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Content
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Datastore
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Deployment
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Guest
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Identity
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Inventory
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.ISO
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.LCM
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.NamespaceManagement
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Namespaces
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.OVF
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Services
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Storage
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.SystemConfig
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Tagging
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Topology
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.TrustedInfrastructure
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.VCHA
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.Vm
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vCenter.VmTemplate
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphere.vStats
    d-----        2/17/2022  11:25 AM                VMware.Sdk.vSphereRuntime
    d-----        2/17/2022  11:25 AM                VMware.Vim
    d-----        2/17/2022  11:25 AM                VMware.VimAutomation.Cis.Core
    d-----        2/17/2022  11:25 AM                VMware.VimAutomation.Cloud
    d-----        2/17/2022  11:25 AM                VMware.VimAutomation.Common
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Core
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Hcx
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.HorizonView
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.License
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Nsxt
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Sdk
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Security
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Srm
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Storage
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.StorageUtility
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Vds
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.Vmc
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.vROps
    d-----        2/17/2022  11:26 AM                VMware.VimAutomation.WorkloadManagement
    d-----        2/17/2022  11:26 AM                VMware.VumAutomation


  • 4.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 12:43 PM

    Did you "unblock" the files you downloaded with Save-Module?

    Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules\VMware*' -Recurse |
    Unblock-File


  • 5.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 01:30 PM

    Same thing, it's strange as I was trying to run a PS script (you helped me with) to run as a scheduled task, it would complete, but never actually work, but always does ig I run from ISE.

    I'm using my domain admin account, but will try a service account once I get this fixed.

    Anyway so to test the .ps1 script I run powershell as me from CMD;

     

    runas /user:mydomain\myadminaccount powershell

     

    I run the .ps1 below and you can see the errors, there are many more after, but it's not seeing the modules.

     

    PS C:\Scripts\VMware> .\DatastoreCluster_2_Influx_all_main.ps1
    WARNING: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a
     better product. You can join using the following command:
    
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
    
    VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to
    improve its products and services, to fix problems, and to advise you on how best to deploy and use our products.  As
    part of the CEIP, VMware collects technical information about your organization’s use of VMware products and services
     on a regular basis in association with your organization’s VMware license key(s).  This information does not
    personally identify any individual.
    
    For more details: type "help about_ceip" to see the related help article.
    
    To disable this warning and set your preference use the following command and restart PowerShell:
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.
    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module
    could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1:11 char:1
    + Connect-VIServer -Server vcenter.mydomain.com -Credential $cre ...

     

     

    Now it I then run $env:PSModulePath in the same windows and run the above again by using the up arrow to run my last ps1 command it all works.

    If I close the PS window I started in CMD and try this again, I get the same issue and I need to run $env:PSModulePath again to get it to work.

    Strange eh?



  • 6.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 01:37 PM

    There is something fishy in your environment I'm afraid.
    You shouldn't need to run $env:PSModulePath to get a script to run.

    To go back to the beginning, why do you use Save-Module?
    Is the station where you run your scripts not able to connect to the Internet?
    It is a lot easier to do just Install-Module.

    Also, what does this show?

    $env:PSModulePath.Split(';')


  • 7.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 02:01 PM

    When I run from the internet it just hangs, what's the best way to clean this install up and install fresh from the internet?

     

     

    PS C:\Scripts\VMware> $env:PSModulePath.Split(';')
    C:\Users\myadminaccount\Documents\WindowsPowerShell\Modules
    C:\Program Files\WindowsPowerShell\Modules
    C:\Windows\system32\WindowsPowerShell\v1.0\Modules
    C:\Program Files\Citrix\PowerShellModules\
    C:\Program Files\Citrix\XenDesktopPoshSdk\Module\Citrix.XenDesktop.Admin.V1\
    C:\Program Files\Veeam\Backup and Replication\Console\
    C:\Program Files\Veeam\Backup and Replication\Explorers\Exchange\
    C:\Program Files\Veeam\Backup and Replication\Explorers\SharePoint\
    C:\Program Files\Veeam\Backup and Replication\Explorers\SQL\
    C:\Program Files\Veeam\Backup and Replication\Explorers\ActiveDirectory\
    C:\Program Files\Veeam\Backup and Replication\Explorers\Teams\
    C:\Program Files\Veeam\Backup and Replication\Explorers\Oracle\

     

    If I run from ISE it always works.

    If use the below from CMD:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1

     

    I get

    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module
    could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1:11 char:1
    + Connect-VIServer -Server vcenter.mydomsin.com -Credential $cre ...
    + ~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
    Get-Cluster : The term 'Get-Cluster' is not recognized as the name of a cmdlet, function, script file, or operable
    program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


  • 8.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 03:18 PM

    I would remove all PowerCLI related folders.
    You can check where all the PowerCLI folders are with

    Get-Module -Name VMware* -ListAvailable


    When that is done, install (use the Verbose switch).

    Install-Module -Name VMware.PowerCLI -Verbose

    Once installed, check where all the PowerCLI modules are installed (see Get-Module cmdlet above).
    Then check if the parent folder, for all the PowerCLI folders is included in $env:PSModulePath.

    When that is done, open a PS prompt (powershell.exe).
    Then try a Connect-VIServer to your vCenter




  • 9.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 07:52 PM

    Thanks, I'm doing this now.  It shows they are in 3 locations which I've removed.

    When I install I get this below, as I want to also run with another account (service account) as well as my admin account what should I use?

     

     

    Install-Module : Administrator rights are required to install modules in 'C:\Program Files\WindowsPowerShell\Modules'.
    Log on to the computer with an account that has Administrator rights, and then try again, or install
    'C:\Users\myadminaccount\Documents\WindowsPowerShell\Modules' by adding "-Scope CurrentUser" to your command. You
    can also try running the Windows PowerShell session with elevated rights (Run as Administrator).

     

     

    I'm trying with:

     

     

     Install-Module -Name VMware.PowerCLI -Scope CurrentUser -Verbose

     

     

    Edit here is the install, it only installed 4 folders.

    https://pastebin.com/0EzJZ8x9



  • 10.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 08:03 PM

    Yes, when you are not a local admin you  can't write in C:\Program Files.
    But with the Scope CurrentUser it will go in C:\Users\<your username>\Documents\PowerShell\Modules.
    Just make sure that this folder is listed in $env:PSModulePath



  • 11.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 08:12 PM

    This is my domain admin account.

    Did you see the output link, only 4 folders get installed.

    Also it is listed in $env:PSModulePath but no commands work as it only installed 4 modules for some reason.



  • 12.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 08:52 PM

    Do you by any chance have the Hyper-V module installed on that station?

    Get-Module -Name Hyper-V -ListAvailable

    Since that module contains cmdlets with the same name as some PowerCLI cmdlets, you will have to use the AllowClobber switch on the Install-Module cmdlet.

    Also, there are numerous PowerCLI modules for which the download seems to have failed.

    VERBOSE: Hash for package 'VMware.VimAutomation.Srm' does not match hash provided from the server.

    I just tested a similar fresh install, and that succeeded.

    You might try adding the SkipPublisherCheck switch.

    Try with (after removing the PowerCLI folders)

    Install-Module -Name VMware.PowerCLI -Scope CurrentUser -AllowClobber -SkipPublisherCheck -Force -Verbose

     



  • 13.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 17, 2022 10:14 PM

    Yeah Hyper-V is there:

     

     

     

     

    Get-Module -Name Hyper-V -ListAvailable
    
    
        Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
    
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Binary     2.0.0.0    Hyper-V                             {Add-VMAssignableDevice, Add-VMDvdDrive, Add-VMFibreChanne...
    Binary     1.1        Hyper-V                             {Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMHardDiskDriv...

     

     

     

     

     

    So I ran:

     

     

     

     

    Install-Module -Name VMware.PowerCLI -Scope CurrentUser -AllowClobber -SkipPublisherCheck -Force -Verbose

     

     

     

     

     

    Much more installed, not sure anything was missued:

    https://pastebin.com/0fJ7Xdtq

     

     

     

     

     Get-Module -Name VMware* -ListAvailable
    
    
        Directory: C:\Users\admin.andy.white\Documents\WindowsPowerShell\Modules
    
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     12.5.0.... VMware.CloudServices                {Connect-Vcs, Disconnect-Vcs, Get-VcsOrganizationRole, Get...
    Script     7.0.3.1... VMware.DeployAutomation             {Add-CustomCertificate, Add-DeployRule, Add-ProxyServer, A...
    Script     7.0.3.1... VMware.ImageBuilder                 {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-Esx...
    Manifest   12.5.0.... VMware.PowerCLI
    Script     12.5.0.... VMware.PowerCLI.Sdk
    Script     12.5.0.... VMware.PowerCLI.Sdk.Types
    Script     12.5.0.... VMware.PowerCLI.VCenter             {Get-VIMachineCertificate, Get-VITrustedCertificate, Remov...
    Script     12.5.0.... VMware.PowerCLI.VCenter.Types.Ap...
    Script     12.5.0.... VMware.PowerCLI.VCenter.Types.Ce...
    Script     1.0.106... VMware.Sdk.Runtime                  {Get-ServerConfiguration, New-ServerConfiguration, Add-Ser...
    Manifest   1.0.104... VMware.Sdk.vSphere
    Script     3.0.104... VMware.Sdk.vSphere.Appliance        {Invoke-GetItemHealthMessages, Invoke-GetHealthSettings, I...
    Script     2.0.104... VMware.Sdk.vSphere.Appliance.Access {Invoke-GetAccessConsolecli, Invoke-SetAccessConsolecli, I...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Health {Invoke-GetHealthApplmgmt, Invoke-GetHealthDatabase, Invok...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Inf... {Invoke-ExportInfraprofileConfigs, Invoke-ImportInfraprofi...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Loc... {Invoke-GetLocalAccountsGlobalPolicy, Invoke-SetLocalAccou...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Log... {Invoke-GetLoggingForwarding, Invoke-SetLoggingForwarding,...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Net... {Invoke-CreateNetworkingDnsDomains, Invoke-ListNetworkingD...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Rec... {Invoke-GetSystemNameArchive, Invoke-ListSystemNameArchive...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Sup... Invoke-GetSupportBundleComponents
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.System {Invoke-GetSystemGlobalFips, Invoke-SetSystemGlobalFips, I...
    Script     1.0.104... VMware.Sdk.vSphere.Appliance.Update {Invoke-InstallVersionPending, Invoke-ListUpdatePending, I...
    Script     1.0.104... VMware.Sdk.vSphere.Cis              {Invoke-CreateSession, Invoke-DeleteSession, Invoke-GetSes...
    Script     1.0.104... VMware.Sdk.vSphere.Cis.Tagging      {Invoke-AddToUsedByCategoryId, Invoke-CreateCategory, Invo...
    Script     1.0.104... VMware.Sdk.vSphere.Content          {Invoke-GetContentConfiguration, Invoke-UpdateContentConfi...
    Script     1.0.104... VMware.Sdk.vSphere.ContentLibrary   {Invoke-GetLibraryItemVersionLibraryChanges, Invoke-ListLi...
    Script     1.0.104... VMware.Sdk.vSphere.Esx.Hcl          {Invoke-DownloadHclCompatibilityDataAsync, Invoke-GetHclCo...
    Script     1.0.104... VMware.Sdk.vSphere.Esx.Hosts        {Invoke-ListHostSoftwareInstalledComponents, Invoke-GetSof...
    Script     1.0.104... VMware.Sdk.vSphere.Esx.Settings     {Invoke-DeleteClusterDraftSoftwareAddOn, Invoke-GetCluster...
    Script     1.0.104... VMware.Sdk.vSphere.VAPI.Metadata    {Invoke-GetCliCommand, Invoke-GetCliCommandFingerprint, In...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter          {Invoke-GetCluster, Invoke-ListCluster, Invoke-CreateDatac...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Authe... Invoke-CreateAuthenticationToken
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.CertM... {Invoke-GetCertificateManagementSigningCertificate, Invoke...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Content  {Invoke-CreateContentRegistriesHarbor, Invoke-DeleteRegist...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Datas... Invoke-GetDatastoreDefaultPolicy
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Deplo... {Invoke-CheckMigrateActiveDirectory, Invoke-CancelDeployme...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Guest    {Invoke-CreateGuestCustomizationSpecs, Invoke-DeleteNameGu...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Identity {Invoke-CreateIdentityProviders, Invoke-DeleteProviderIden...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Inven... {Invoke-GetInventoryDatastore, Invoke-GetInventoryNetwork}
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.ISO      {Invoke-MountIsoImage, Invoke-UnmountIsoImage, Initialize-...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.LCM      {Invoke-CreateLcmDiscoveryAssociatedProducts, Invoke-Delet...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Names... {Invoke-ListNamespaceManagementSoftwareClusterAvailableVer...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Names... {Invoke-CreateNamespaceDomainSubjectAccess, Invoke-DeleteN...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.OVF      {Invoke-ListOvfExportFlag, Invoke-ListOvfImportFlag, Invok...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Services {Invoke-GetService, Invoke-GetServices, Invoke-RestartServ...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Storage  {Invoke-ListPoliciesEntitiesCompliance, Invoke-CheckCompat...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Syste... {Invoke-GetSystemConfigDeploymentType, Invoke-SetSystemCon...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Tagging  Invoke-ListAssociations
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Topology {Invoke-GetNodeTopology, Invoke-ListTopologyNodes, Invoke-...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Trust... {Invoke-CreateTrustedInfrastructureTrustAuthorityHostsAtte...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.VCHA     {Invoke-GetClusterActive, Invoke-DeployVchaClusterAsync, I...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.Vm       {Invoke-GetVmHardwareBoot, Invoke-UpdateVmHardwareBoot, In...
    Script     1.0.104... VMware.Sdk.vSphere.vCenter.VmTem... {Invoke-CheckInTemplateLibraryItemVmCheckOuts, Invoke-Chec...
    Script     1.0.104... VMware.Sdk.vSphere.vStats           {Invoke-CreateStatsAcqSpecs, Invoke-DeleteIdStatsAcqSpecs,...
    Script     1.0.104... VMware.Sdk.vSphereRuntime           {New-vSphereServerConfiguration, Get-vSphereServerConfigur...
    Script     7.0.3.1... VMware.Vim
    Script     12.5.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}
    Script     12.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, G...
    Script     12.5.0.... VMware.VimAutomation.Common         {Get-PowerCLIContext, Get-Task, New-OAuthSecurityContext, ...
    Script     12.5.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAd...
    Script     12.5.0.... VMware.VimAutomation.Hcx            {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance...
    Script     12.5.0.... VMware.VimAutomation.HorizonView    {Connect-HVServer, Disconnect-HVServer}
    Script     12.0.0.... VMware.VimAutomation.License        Get-LicenseDataManager
    Script     12.5.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtGlobal...
    Script     12.5.0.... VMware.VimAutomation.Sdk            Get-ErrorReport
    Script     12.3.0.... VMware.VimAutomation.Security       {Add-AttestationServiceInfo, Add-KeyProviderServiceInfo, A...
    Script     12.3.0.... VMware.VimAutomation.Srm            {Connect-SrmServer, Disconnect-SrmServer}
    Script     12.5.0.... VMware.VimAutomation.Storage        {Add-EntityDefaultKeyProvider, Add-KeyManagementServer, Ad...
    Script     1.6.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore
    Script     12.5.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, E...
    Script     12.5.0.... VMware.VimAutomation.Vmc            {Add-VmcSddcHost, Connect-Vmc, Disconnect-Vmc, Get-AwsAcco...
    Script     12.5.0.... VMware.VimAutomation.vROps          {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-O...
    Script     12.4.0.... VMware.VimAutomation.WorkloadMan... {Disable-WMCluster, Enable-WMCluster, Get-WMCluster, Get-W...
    Script     12.1.0.... VMware.VumAutomation                {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Complia...

     

     

     

     

     

    So if I run my ps script in ISE it runs.

    If I open CMD and run this it works:

     

     

     

     

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1

     

     

     

     

     

    If I put the above into Windows Scheduler it fails:

     

     

     

     

    To disable this warning and set your preference use the following command and restart PowerShell:
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.
    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the
    module could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1:11 char:1
    + Connect-VIServer -Server vvsupport1.thisisglobal.com -Credential $cre ...
    + ~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
    Get-Cluster : The 'Get-Cluster' command was found in the module 'VMware.VimAutomation.Core', but the module could
    not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1:14 char:20
    +     ClusterName = (Get-Cluster -Name 'London')
    +                    ~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Get-Cluster:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
    Write-Influx : Cannot bind argument to parameter 'Metrics' because it is null.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1:22 char:73
    + ... re LonClusterSpaceGB -Tags @{host="London"} -Metrics $Metrics -Databa ...
    +                                                          ~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Write-Influx], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Write-Influx

     

     

     

     

     

    If I try using my service account and not my domain admin account, which is a local admin and in the local policy to run batch jobs:

     

     

     

     

    runas /user:mydomain\svc-vmware powershell

     

     

     

     

     

    Then I get this:

     

     

     

     

    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\svc.vmwareinfo\Documents\WindowsPowerShell\Modules\VMware.VimAutomation.Common\VMware.VimAutomation.Common.psm
    1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): q
    PS C:\Windows\system32> C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main_svcaccount.ps1
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\svc-vmware\Documents\WindowsPowerShell\Modules\VMware.VimAutomation.Common\VMware.VimAutomation.Common.psm
    1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"):

     

     

     

     

    If I keep type 'R' then some work some error:

     

     

    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run C:\Users\svc-vmware\Documents\WindowsPowerShell\Modules\VMware.Vim\VMware.Vim.psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): R
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\svc-vmware\Documents\WindowsPowerShell\Modules\VMware.VimAutomation.Cis.Core\VMware.VimAutomation.Cis.Core
    .psm1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): R
    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module
    could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main_svcaccount.ps1:11 char:1
    + Connect-VIServer -Server vvsupport1.thisisglobal.com -Credential $cre ...
    + ~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\svc-vmware\Documents\WindowsPowerShell\Modules\VMware.VimAutomation.Core\VMware.VimAutomation.Core.psm1?

     

     



  • 14.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 06:50 AM

    Looks like the execution policy (Get-ExecutionPolicy) for that service account is not set to at least 'RemoteSigned'.
    Change it with Set-ExecutionPolicy



  • 15.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 08:53 AM

    Thanks so far for your help I truly appreciate this.

    1. This is what I get if I try that under the service account and my domain admin account.

    Service account - I've just set the ExecutionPolicy

    PS C:\Windows\system32> Get-ExecutionPolicy
    Unrestricted

     

    Run the Script via CMD:

    PS C:\Windows\system32> C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main_svcaccount.ps1
    
    Security warning
    Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
    computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
    message. Do you want to run
    C:\Users\svc.vmwareinfo\Documents\WindowsPowerShell\Modules\VMware.VimAutomation.Common\VMware.VimAutomation.Common.psm
    1?
    [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"):

     

    So I add:

    Get-ChildItem -Path 'C:\Users\svc.vmwareinfo\Documents\WindowsPowerShell\Modules\' -Recurse | Unblock-File

     

    Run again:

    PS C:\Windows\system32> C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main_svcaccount.ps1
    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module
    could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main_svcaccount.ps1:11 char:1
    + Connect-VIServer -Server vvsupport1.thisisglobal.com -Credential $cre ...
    + ~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
    Get-Cluster : 18/02/2022 08:28:41       Get-Cluster             You are not currently connected to any servers. Please connect first

     

    2. PowerShell ISE as this account or my Domain Admin = all works

    3.  If I try using my domain admin account by just opening PS and running the .ps1 it works.

    4.  If I run as my domain admin account from a command prompt like a schedule task would be:

    runas /user:mydomain\mydomainaccount powershell

     

    It fails

    Loading personal and system profiles took 1491ms.
    PS C:\Windows\system32> & 'C:\Scripts\vmware\DatastoreCluster_2_Influx_all_main.ps1'
    WARNING: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a
     better product. You can join using the following command:
    
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
    
    VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to
    improve its products and services, to fix problems, and to advise you on how best to deploy and use our products.  As
    part of the CEIP, VMware collects technical information about your organization’s use of VMware products and services
     on a regular basis in association with your organization’s VMware license key(s).  This information does not
    personally identify any individual.
    
    For more details: type "help about_ceip" to see the related help article.
    
    To disable this warning and set your preference use the following command and restart PowerShell:
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.
    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module
    could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\vmware\DatastoreCluster_2_Influx_all_main.ps1:11 char:1
    + Connect-VIServer -Server vvsupport1.thisisglobal.com -Credential $cre ...
    + ~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule


  • 16.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 10:15 AM

    Where are the PowerCLI modules installed?
    What is in $env:PSModulePath?

    I suspect if they are installed for CurrentUser with your original account that the service account can't reach those?
    The service account might probably be using another installation of PowerCLI.
    Under the service account remove all PowerCLI folders and do a fresh install with the same Install-Module you used yesterday.

    The discrepancy with ISE might be that ISE is doing some settings in the ISE profile.
    Can you check what is those ISE profiles?
    See How to Use Profiles in Windows PowerShell ISE - PowerShell | Microsoft Docs



  • 17.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 01:14 PM

    If we forget the service account at them moment as my domain admin account gets the same issues and I've cleared out the modules and reinstalled.

    As you know ISE works 

    Below I just my open powershell as another user (my domain admin account), it finds the module but can't run:

    .\DatastoreCluster_2_Influx_all_main.ps1
    WARNING: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a
    better product. You can join using the following command:
    
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true
    
    VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to
    improve its products and services, to fix problems, and to advise you on how best to deploy and use our products.  As
    part of the CEIP, VMware collects technical information about your organization’s use of VMware products and services
    on a regular basis in association with your organization’s VMware license key(s).  This information does not
    personally identify any individual.
    
    For more details: type "help about_ceip" to see the related help article.
    
    To disable this warning and set your preference use the following command and restart PowerShell:
    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.
    Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module
    could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.
    At C:\Scripts\VMware\DatastoreCluster_2_Influx_all_main.ps1:11 char:1
    + Connect-VIServer -Server vvsupport1.mydomain.com -Credential $cre ...
    + ~~~~~~~~~~~~~~~~
       + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException
       + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
    
    PS C:\Scripts\VMware> $env:PSModulePath
    C:\Users\myadminaccount\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files\Citrix\PowerShellModules\;C:\Program Files\Citrix\XenDesktopPoshSdk\Module\Citrix.XenDesktop.Admin.V1\;C:\Program Files\Veeam\Backup and Replication\Console\;C:\Program Files\Veeam\Backup and Replication\Explorers\Exchange\;C:\Program Files\Veeam\Backup and Replication\Explorers\SharePoint\;C:\Program Files\Veeam\Backup and Replication\Explorers\SQL\;C:\Program Files\Veeam\Backup and Replication\Explorers\ActiveDirectory\;C:\Program Files\Veeam\Backup and Replication\Explorers\Teams\;C:\Program Files\Veeam\Backup and Replication\Explorers\Oracle\
    PS C:\Scripts\VMware>

     

    You can see the location

     PS C:\Scripts\VMware> $env:PSModulePath.Split(';')
    C:\Users\mydomainaccount\Documents\WindowsPowerShell\Modules
    C:\Program Files\WindowsPowerShell\Modules
    C:\Windows\system32\WindowsPowerShell\v1.0\Modules
    C:\Program Files\Citrix\PowerShellModules\
    C:\Program Files\Citrix\XenDesktopPoshSdk\Module\Citrix.XenDesktop.Admin.V1\
    C:\Program Files\Veeam\Backup and Replication\Console\
    C:\Program Files\Veeam\Backup and Replication\Explorers\Exchange\
    C:\Program Files\Veeam\Backup and Replication\Explorers\SharePoint\
    C:\Program Files\Veeam\Backup and Replication\Explorers\SQL\
    C:\Program Files\Veeam\Backup and Replication\Explorers\ActiveDirectory\
    C:\Program Files\Veeam\Backup and Replication\Explorers\Teams\
    C:\Program Files\Veeam\Backup and Replication\Explorers\Oracle\
    PS C:\Scripts\VMware>

    All I want to do is run a few powershell scripts via Windows Scheduler.

    Why would it find but not load?



  • 18.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 01:19 PM

    What do you get when you

    Import-Module VMware.VimAutomation.Core -Verbose


  • 19.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 01:34 PM

    I get this:

    Import-Module VMware.VimAutomation.Core
    Import-Module : Cannot find a variable with the name 'AmsiContext'.
    At line:1 char:1
    + Import-Module VMware.VimAutomation.Core
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (AmsiContext:String) [Import-Module], ItemNotFoundException
        + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand


  • 20.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 01:38 PM


  • 21.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 02:17 PM

    Oh wow yes it is, let me check the article.



  • 22.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 04:15 PM

    I just want to say you are one of the most helpful persons I have ever met on a tech forum.

    That fixed it!

    Sorry to of wasted your time.

    I'm sure now I have it all running I will have some more powershell scripts I need to work on as I lost a few days working on this.

    The next PS scripts I want to get into Influx will be, snapshots showing size, VMs based on a tag name showing their VMtool version, Datastore names and sizes.

    I'll work on these next week.

    Grafana is starting to show some nice info now!!



  • 23.  RE: Trouble installing PowerCLI on Windows server

    Posted Feb 18, 2022 01:37 PM

    Also if I just open powershell (not the ISE one) and run the .ps1 scripts they work.

    It seems to be only when I use a 'runas' which is what the Task Scheduler would do I guess and why that fails too.