-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMerge-EsxImageProfile.ps1
76 lines (64 loc) · 2.22 KB
/
Merge-EsxImageProfile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function Merge-EsxImageProfile{
<#
.SYNOPSIS
Create a new EsxImageProfile by merging two EsxImageProfile and keep highest vib.
.DESCRIPTION
Create a new EsxImageProfile by merging two EsxImageProfile and keep highest vib.
Based on "New-EsxImageProfile"
Requirement: Compare-EsxImageProfilePlus
.NOTES
Author: Christophe Calvet
Blog: http://www.thecrazyconsultant.com/
.PARAMETER Profile1
First Image profile
.PARAMETER Profile2
Second Image Profile
.EXAMPLE
$NewProfile = Merge-EsxImageProfile $Profile1 $Profile2 -AcceptanceLevel "PartnerSupported" -OverrideProfileWithSameName
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[VMware.ImageBuilder.Types.ImageProfile]$Profile1,
[Parameter(Mandatory=$true)]
[VMware.ImageBuilder.Types.ImageProfile]$Profile2,
$NewName,
$NewVendor,
$NewDescription,
[ValidateSet('VMwareCertified','VMwareAccepted','PartnerSupported','CommunitySupported')]
[string]$AcceptanceLevel = "VMwareCertified",
[switch]$OverrideProfileWithSameName
)
process{
if(!$NewName){
$NewName = "$($Profile1.name)" + "___" + "$($Profile2.name)"
}
if(!$NewVendor){
$NewVendor = "$($Profile1.vendor)" + "___" + "$($Profile2.vendor)"
}
if(!$NewDescription){
$NewDescription = "$($Profile1.Description)" + "___" + "$($Profile2.Description)"
}
if($OverrideProfileWithSameName){
get-EsxImageProfile -name $NewName | Remove-EsxImageProfile
}
#Put latest VIB in one array $SoftwarePackage
$SoftwarePackage = @()
$CompareResult = Compare-EsxImageProfilePlus $Profile1 $Profile2 -IncludeVibInOutput
$CompareResult | foreach-object{
$CurrentVib = $_
$Analysis = $_.Analysis
$Name = $_.name
switch($Analysis){
OnlyInRef{$SoftwarePackage += $CurrentVib.VibRef}
OnlyInComp{$SoftwarePackage += $CurrentVib.VibComp}
Identical{$SoftwarePackage += $CurrentVib.VibRef}
UpgradeFromRef{$SoftwarePackage += $CurrentVib.VibComp}
DowngradeFromRef{$SoftwarePackage += $CurrentVib.VibRef}
Default{Write-Error "The output of Compare-EsxImageProfilePlus is wrong"}
}
}
#Build new profile
New-EsxImageProfile -NewProfile -name $NewName -vendor $NewVendor -SoftwarePackage $SoftwarePackage -AcceptanceLevel $AcceptanceLevel -Description $NewDescription
}
}