Created
May 12, 2014 12:55
-
-
Save lrivallain/b74a87c5c01a53ee242f to your computer and use it in GitHub Desktop.
PowerCli - Mise à jour du VMX de templates de machines virtuelles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load PowerCli Snapin | |
if ((Get-PSSnapin -Name VMware.Vimautomation.Core -ErrorAction SilentlyContinue) -eq $null ) { | |
Add-PsSnapin VMware.Vimautomation.Core | |
} | |
# vCenter server | |
$VC = "monvcenter.domain.tld" | |
$Username = "domain\monuser" | |
# connecting vCenter | |
$Credentials = get-credential -credential $Username | |
$ConnVC = Connect-VIServer -server $($VC.IP) -Credential $Credentials -warningaction 'silentlycontinue' | |
# config change for updateVMWareTools | |
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec | |
$vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue | |
$vmConfigSpec.extraconfig[0].Key="isolation.tools.guestInitiatedUpgrade.disable" | |
$vmConfigSpec.extraconfig[0].Value="true" | |
# update all templates | |
$templates = Get-template | |
foreach ($tpl in $templates) { | |
Write-host -foreground blue "Template: $($tpl.Name)" | |
Write-host -foreground gray " Converting to VM" | |
$vm = Set-Template -Template $tpl -ToVM | |
Write-host -foreground gray " updating VMX" | |
($vm | Get-View).ReconfigVM($vmConfigSpec) | |
Write-host -foreground gray " Converting to Template back" | |
($vm | Get-View).MarkAsTemplate() | Out-Null | |
Write-host -foreground gray " End of update process" | |
} | |
# clean leave | |
Disconnect-VIServer -Confirm:$false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment