-
Notifications
You must be signed in to change notification settings - Fork 3
/
vCenterMigrationBase.ps1
182 lines (151 loc) · 5.52 KB
/
vCenterMigrationBase.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
###################################################
## vCenter Granual Migration Wizard
## VMworld Hackathon Team
##
$Version = "1.0"
$LastUpdated = "08/29/2017"
$ProgramDescription = "Assists with partial vCenter Migrations of specific items/objects"
$ProgramName = "vCenter Granular Migration Wizard"
$MigrationChoices = `
'vCenter Server Settings',`
'vCenter Alarm Migration',`
'VIRole Migration',`
'Folder Migration',`
'Permissions Migration',`
'Custom Attribute Migration',`
'Customization Spec Migration',`
'vSphere Tag Migration',`
'VUM Baseline Migration',`
'Distritubed Switch Migration',`
'Cluster Attribute Migration',`
'Exit'
#region Check System Requirements and Set PowerCLIConfig
if (!(Get-Module VMware.PowerCLI)) {
Write-Host "[Loading PowerCLI]" -ForegroundColor Cyan
Import-Module VMware.PowerCLI
}
# Setting PowerCLI Configuration and Load Additional Modules
try {
Disconnect-VIServer * -Force -Confirm:$false -ErrorAction Ignore
} catch {}
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -InvalidCertificateAction Ignore -Scope Session -Confirm:$false
#endregion
#region Helper Functions
###################################################################################
# Get-Selection : Takes a simple description and an array of objects to choose
###################################################################################
Function Get-Selection {
[cmdletbinding()]
param(
[Parameter(Position=0, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$SelectionTitle,
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$SelectionList,
[Parameter(Position=2)]
$SelectionProperty,
[Parameter(Position=3)]
$Default
)
Write-Host $('*' * ($SelectionTitle.length + 2)) -ForegroundColor Cyan
Write-Host " $SelectionTitle " -ForegroundColor Cyan
Write-Host $('*' * ($SelectionTitle.length + 2 )) -ForegroundColor Cyan
$MenuCount = 0
foreach ($Item in $SelectionList) {
## Add index
$MenuCount++
$SelectionList[$MenuCount-1] | Add-Member -MemberType noteproperty -Name ItemIndex -Value $MenuCount -Force
## Build out MenuLine
if (($SelectionProperty) -and ($Item.$SelectionProperty)) {
Write-Host " $MenuCount`:".padright(3) "$($Item.$SelectionProperty)"
} else {
Write-Host " $MenuCount`:".padright(3) "$Item"
}
}
Write-Host $('*' * ($SelectionTitle.length + 2)) -ForegroundColor Cyan
Do {
try {
[int]$Selection = Read-Host "Choose an option from above (1-$MenuCount)[$Default]"
} catch {}
if (($Selection -eq "") -and ($Default)) {
$Selection = $Default
}
} until (($Selection -ge 1) -and ($Selection -le $MenuCount))
$SelectedItem = $SelectionList[$Selection-1]
return $SelectedItem
}
###################################################################################
# Get-YesNo : Asks a y/n question and returns True/False based on response
###################################################################################
Function Get-YesNo {
param(
[Parameter(Position=0, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$Question,
[Parameter(Position=1)]
[ValidateNotNullOrEmpty()]
[String]$Default
)
Do {
$Answer = Read-Host "$Question (y/n)[$Default]"
if (($Answer -eq "") -and ($Default)) {
$Answer = "$Default"
}
switch ($Answer) {
'y' { Return $true }
'n' { Return $false }
default { $Answer = $null }
}
} while ($Answer -eq $null)
}
#endregion
$MigrationData = "MigrationData"
########################################
## MAIN Section
########################################
Clear-Host
Write-Host "*************************************************" -ForegroundColor Green
Write-Host "** " -f Green -NoNewline ; Write-Host "$ProgramName" -ForegroundColor Cyan
Write-Host "** " -f Green -NoNewline ; Write-Host "Version: $Version " -ForegroundColor Cyan
Write-Host "** " -f Green -NoNewline ; Write-Host "Last Update: $LastUpdated " -ForegroundColor Cyan
Write-Host "*************************************************" -ForegroundColor Green
Write-Host
Write-Host "WHAT THIS PROGRAM DOES:" -ForegroundColor Yellow
Write-Host
Write-Host "> $ProgramDescription"
Write-Host
Write-Host "*******************************************************************************************" -ForegroundColor Green
Read-Host "Press <Enter> to begin"
## Connect to SOURCE and TARGET vCenters
Do {
$SourceVC = Connect-VIServer (Read-Host "Type SOURCE vCenter") -User none
} while (!$SourceVC)
Do {
$TargetVC = Connect-VIServer (Read-Host "Type TARGET vCenter") -User none
} while (!$TargetVC)
Do {
## Select Migration Action
Clear-Host
$MigrationChoice = Get-Selection -SelectionTitle 'Please Select a migration action' -SelectionList $MigrationChoices
Clear-Host
switch -wildcard ($MigrationChoice) {
VIRole* {
Write-Host '[Launching VIRole Migration Wizard]' -ForegroundColor Cyan
$SubScript = "./Module-RoleMigration.ps1"
. $SubScript
}
Folder* {
Write-Host '[Launching Folder Migration Wizard]' -ForegroundColor Cyan
$SubScript = "./Module-FolderMigration.ps1"
. $SubScript
}
Permissions* {
Write-Host '[Launching Permissions Migration Wizard]' -ForegroundColor Cyan
}
Cluster* {
Write-Host '[Launching Cluster Migration Wizard]' -ForegroundColor Cyan
}
default { Write-Host '[Exiting]' -ForegroundColor Cyan }
}
} while ($MigrationChoice -ne 'Exit')