In the past I’ve written about using some PowerCLI extensions from the community repository to rekey individual objects, to rekey all objects, and to migrate from one key provider to another. I’ve recently discovered that the native PowerCLI commands support rekeying of VM and host keys, although not vSAN keys.
It is straightforward to rekey a vSAN cluster using the vCenter UI, and this has the side benefit that it will rekey your host encryption keys as well. But if you want to rekey virtual machines or host encryption keys directly, you could use a script like the following without needing to install the community modules:
$kp = Get-KeyProvider new-kmip
foreach($vm in Get-VM) {
if($vm.ExtensionData.Config.KeyId) {
Set-VM $vm -KeyProvider $kp -Confirm:$false
}
}
foreach($vmhost in Get-VMHost) {
if($vmhost.ExtensionData.Runtime.CryptoState -eq "safe") {
Set-VMHost $vmhost -KeyProvider $kp
}
}
One thought on “PowerCLI native rekey capabilities”