VMware Cloud Community
dalo
Hot Shot
Hot Shot
Jump to solution

use different PowerCLI versions parallel

That's maybe an easy one but I don't get it:

For debugging purposes I want to run a older PowerCLI Version besides the actual Version.

I know the "-RequiredVersion" switch of the install-module but I was not really lucky with this.

Then I found the "save-powercli" module, this downloads all the modules into a folder.

But how do I use the modules from this folder with the older version? import-module, path or what else?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I have been playing with the Save-PowerCLI function, and I made some changes.

Can you try the attached version?
For example

Save-PowerCLI -Path C:\PCLI10_2 -RequiredVersion '10.2.0.9372002'


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

You can use the full path to a module on the Import-Module cmdlet.

Import-Module C:\Otherversion\VMware.VimAutomation.Core


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

dalo
Hot Shot
Hot Shot
Jump to solution

thanks for the fast response, but I don't get it already, sorry.

I made:

Save-PowerCLI -requiredVersion '10.2.0.9372002' -path E:\pcli\10 -simple

then

Import-Module E:\pcli\10\VMware.VimAutomation.Core\

this returns me "...no valid module file was found in any module directory"

then

Import-Module E:\pcli\10\VMware.VimAutomation.Core\VMware.VimAutomation.Core.psd1

this seems to work, but it seems that the Version 11.2 is still active:

get-module VMware.VimAutomation.Core

ModuleType Version    Name                                ExportedCommands

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

Script     11.2.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...}

Script     11.2.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...}

Script     11.2.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...}

0 Kudos
dalo
Hot Shot
Hot Shot
Jump to solution

Ok, one step ahead. I f I do a:

PS E:\pcli> Import-Module E:\pcli\10\VMware.VimAutomation.Core -verbose

VERBOSE: Loading module from path 'E:\pcli\10\VMware.VimAutomation.Core\VMware.VimAutomation.Core.psd1'.

VERBOSE: Importing cmdlet 'Add-PassthroughDevice'.

VERBOSE: Importing cmdlet 'Add-VirtualSwitchPhysicalNetworkAdapter'.

VERBOSE: Importing cmdlet 'Add-VMHost'.

VERBOSE: Importing cmdlet 'Add-VMHostNtpServer'.

VERBOSE: Importing cmdlet 'Connect-VIServer'.

VERBOSE: Importing cmdlet 'Copy-DatastoreItem'.

VERBOSE: Importing cmdlet 'Copy-HardDisk'.

VERBOSE: Importing cmdlet 'Copy-VMGuestFile'.

VERBOSE: Importing cmdlet 'Disconnect-VIServer'.

...

It seems to load everything. but shouldn't it display the loaded version with get-module?

The commands are still the 11.2 ones:

PS E:\pcli> get-command connect-viserver

CommandType     Name                                               Version    Source

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

Cmdlet          Connect-VIServer                                   11.2.0.... VMware.VimAutomation.Core

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The issue might be what is in $env:PSModulePath.
If that one contains the path to a folder where the latest version is installed, it will return that one.
The Get-Module looks at the folders in $env:PSModulePath.
Also don't forget that PS 'reads' all modules in the folders defined $env:PSModulePath, to be able to able to cache the cmdlets (module autoload feature).

You will probably have to adapt the content of the $env:PSModulePath, and store all versions of PowerCLI in different, non-standard folders (i.e. those not defined in $env:PSModulePath).

Then with Import-Module you can load whatever version you want.


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

dalo
Hot Shot
Hot Shot
Jump to solution

It seems that I use the save-powercli command wrong, it downloads the newest Version instead of the older one:

Save-PowerCLI -requiredVersion '10.2.0.9372002' -path E:\pcli10

dir 'E:\pcli10\VMware.VimAutomation.Core\'

    Directory: E:\pcli10\VMware.VimAutomation.Core

Mode                LastWriteTime         Length Name

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

d-----       06.05.2019     16:18                11.2.0.12483638

So I made it manually:

Remove the current PowerCLI, download every Package from PowerShell Gallery unpack, set the $env:PSModulePath and import:

$env:PSModulePath = $env:PSModulePath + ";E:\pcli"

Import-Module 'E:\pcli\vmware.vimautomation.common' -verbose

VERBOSE: Loading module from path 'E:\pcli\vmware.vimautomation.common\vmware.vimautomation.common.psd1'.

VERBOSE: Loading module from path 'E:\pcli\vmware.vimautomation.common\VMware.VimAutomation.Common.psm1'.

get-command Connect-VIServer

CommandType     Name                                               Version    Source

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

Cmdlet          Connect-VIServer                                   10.0.0.... vmware.vimautomation.core

Not as expected, but it works.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try the Save-PowerCLI function from Obtaining Specific PowerCLI Versions from the PowerShell Gallery?


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

0 Kudos
dalo
Hot Shot
Hot Shot
Jump to solution

Yes, I tried this from this Blog entry, as mention above.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I have been playing with the Save-PowerCLI function, and I made some changes.

Can you try the attached version?
For example

Save-PowerCLI -Path C:\PCLI10_2 -RequiredVersion '10.2.0.9372002'


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

0 Kudos
dalo
Hot Shot
Hot Shot
Jump to solution

Thank you, the function works as expected now!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks for confirming that.
I submitted a PR to update the version on the PowerCLI Examples repo.


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

0 Kudos