Plan B to install PowerCLI

Reacties Geen

I found a nice article on installing PowerCLI the new way called Welcome PowerCLI to the PowerShell Gallery – Install Process Updates.

Unfortunatly it didn’t work out so well for me. So I had to work myself around a limit which is most likely cause by my malware protection as it locks a file and frustrates the installation.

It sort of looks like this:

PS C:\windows\system32> Find-Module -Name VMware.PowerCLI

Version    Name                                Repository           Description
-------    ----                                ----------           ----------- VMware.PowerCLI                     PSGallery            This Windows PowerShell module contains VMware.P...

Well that looked just fine …
But this is where it bugged me:

PS C:\windows\system32> Install-Module -Name VMware.PowerCLI -Scope AllUsers

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a
PackageManagement\Install-Package : Package 'VMware.VimAutomation.Srm' failed to be installed because: The process
cannot access the file 'C:\Users\hvdk\AppData\Local\Temp\kt5j1kv3\VMware.VimAutomation.Srm.Views.dll' because it is
being used by another process.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\\PSModule.psm1:1772 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (VMware.VimAutomation.Srm:String) [Install-Package], Exception
    + FullyQualifiedErrorId : Package '{0}' failed to be installed because: {1},Microsoft.PowerShell.PackageManagement

Thanks Trend Micro for keeping me safe, and unproductive.

So here is my alternative approach. Create a new PowerShell Module Directory and add it to my PsModulePath. Then save the modules there and we are all good to go.

mkdir $HOME\PowerShell
$PADJE = [Environment]::GetEnvironmentVariable("PsModulePath")
$PADJE += ";$HOME\PowerShell"
Save-Module -Name VMware.PowerCLI -Path $HOME\PowerShell

And then you are free to program with PowerCLI as you see fit:

PS C:\Users\hvdk> Import-Module VMware.PowerCLI
          Welcome to VMware PowerCLI!

Log in to a vCenter Server or ESX host:              Connect-VIServer
To find out what commands are available, type:       Get-VICommand
To show searchable help for all PowerCLI commands:   Get-PowerCLIHelp
Once you've connected, display all virtual machines: Get-VM
If you need more help, visit the PowerCLI community: Get-PowerCLICommunity

       Copyright (C) VMware, Inc. All rights reserved.

I really start to like PowerShell by now. It seems to be a best of breed of easy going with objects and have rocket power too.

But let’s make this addition to the path more permanently. So let’s open the my profile with: notepad $PROFILE and inster:

$PADJE = [Environment]::GetEnvironmentVariable("PsModulePath")
$PADJE += ";$HOME\PowerShell"

Save the file and check it out by closing Powershell and start a new powershell session:


That’s all for now. I hope it might help you out with similar issues in PowerShell.

Categorie ,


Er zijn nog geen reacties op dit artikel.

react here

Schrijf je reactie hier. De met een * gemarkeerde velden zijn verplicht. Je ziet eerst een voorbeeld en daarna kun je de reactie definitief plaatsen.

← Ouder Nieuwer →