Save-PowerCLI v2.1
- fixed incorrect module version download - added a working cleanup in End Signed-off-by: Luc Dekens <dekens.luc@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
function Save-PowerCLI {
|
||||
function Save-PowerCLI {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery
|
||||
@@ -7,6 +7,9 @@ function Save-PowerCLI {
|
||||
.NOTES
|
||||
Author: 1.0 - Dimitar Milov
|
||||
Author: 2.0 - Kyle Ruddy, @kmruddy
|
||||
Author: 2.1 - Luc Dekens, @LucD22
|
||||
- fixed issue with downloading the correct versions
|
||||
- added a working cleanup of unwanted versions
|
||||
.PARAMETER RequiredVersion
|
||||
Dynamic parameter used to specify the PowerCLI version
|
||||
.PARAMETER Path
|
||||
@@ -62,14 +65,14 @@ function Save-PowerCLI {
|
||||
$AttributeCollection.Add($ValidateSetAttribute)
|
||||
|
||||
# Create and return the dynamic parameter
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [String], $AttributeCollection)
|
||||
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
|
||||
return $RuntimeParameterDictionary
|
||||
}
|
||||
|
||||
begin {
|
||||
$powercliModuleName = 'VMware.PowerCLI'
|
||||
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $RequiredVersion -Repository $Repository
|
||||
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $PSBoundParameters.RequiredVersion -Repository $Repository
|
||||
|
||||
$depsOrder = 'VMware.VimAutomation.Sdk', 'VMware.VimAutomation.Common', 'VMware.Vim', 'VMware.VimAutomation.Cis.Core', 'VMware.VimAutomation.Core', 'VMware.VimAutomation.Nsxt', 'VMware.VimAutomation.Vmc', 'VMware.VimAutomation.Vds', 'VMware.VimAutomation.Srm', 'VMware.ImageBuilder', 'VMware.VimAutomation.Storage', 'VMware.VimAutomation.StorageUtility', 'VMware.VimAutomation.License', 'VMware.VumAutomation', 'VMware.VimAutomation.HorizonView', 'VMware.DeployAutomation', 'VMware.VimAutomation.vROps', 'VMware.VimAutomation.PCloud'
|
||||
$orderedDependencies = @()
|
||||
@@ -94,14 +97,23 @@ function Save-PowerCLI {
|
||||
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) {
|
||||
# Save dependencies with minimum version
|
||||
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path
|
||||
|
||||
# Remove newer dependencies version
|
||||
Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion} | Remove-Item -Confirm:$false -Force -Recurse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Get-Item -Path "$($Path)\*" -PipelineVariable dir |
|
||||
ForEach-Object -Process {
|
||||
$children = Get-ChildItem -Path $dir.FullName -Directory
|
||||
if($children.Count -gt 1){
|
||||
$tgtVersion = $orderedDependencies.GetEnumerator() | where {$_.Name -eq $dir.Name}
|
||||
$children | where{$_.Name -ne $tgtVersion.MinimumVersion} |
|
||||
ForEach-Object -Process {
|
||||
Remove-Item -Path $_.FullName -Recurse -Force -Confirm:$false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($Simple) {
|
||||
|
||||
function FolderCleanup {
|
||||
@@ -142,6 +154,5 @@ function Save-PowerCLI {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user