-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate-templates-to-another-datastore.ps1
36 lines (29 loc) · 1.25 KB
/
migrate-templates-to-another-datastore.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
# Turn off certificate warning
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
# Install power-cli
Install-Module -Name VMware.PowerCLI -Scope AllUsers -SkipPublisherCheck
# Import power-cli module
Import-Module VMware.PowerCLI
# Define variables
$sourceDatastore = "Source Datastore"
$destinationDatastore = "Destination Datastore"
$vCenterServer = "vcenter.domain.local"
$vcenterUsername = "vcenterUsername"
$vCenterPassword = "vCenterPassword"
# Connect to vCenter Server
Connect-VIServer -Server $vCenterServer -User $vcenterUsername -Password $vCenterPassword
# Define variables
$sourceDatastore = "Source Datastore"
$destinationDatastore = "Destination Datastore"
# Get templates on the source datastore
$template_list = Get-Datastore $sourceDatastore | Get-Template
# Move the template to the new location
foreach ($template in $template_list) {
Write-Output "Convert Template $template to VM"
Get-Template $template | Set-Template -ToVM -Confirm:$false
Write-Output "Moving VM to Datastore $destinationDatastore"
get-vm $template | Move-vm -Datastore $destinationDatastore
Write-Output "Convert $template VM to Template"
Get-Vm $template | Set-Vm -ToTemplate -Confirm:$false
Write-Output "$template Completed"
}