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?
I have been playing with the Save-PowerCLI function, and I made some changes.
Can you try the attached version?
For example
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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...}
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
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
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.
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
Yes, I tried this from this Blog entry, as mention above.
I have been playing with the Save-PowerCLI function, and I made some changes.
Can you try the attached version?
For example
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you, the function works as expected now!
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