Azure 基础设施:虚拟机与虚拟网络的部署与管理
1. Azure 虚拟机的部署与管理
在导入现有虚拟机时,为避免导入过程中出现冲突和错误,需先移除这些虚拟机。可使用 Remove-AzureVM 命令,将其添加到 ForEach 循环中 Export-AzureVM 行之后。以下是导出并移除虚拟机的代码示例:
#Exporting Azure VMs State
$VMs = Get-AzureVM -ServiceName 'DevTestFarm'
ForEach ($VM in $VMs)
{
$FileName = $VM.Name + "_VMState.xml"
Export-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name -Path $home\Desktop\VMs\$FileName
#Removing the VM without Deleting VHD
Remove-AzureVM -ServiceName $VM.ServiceName -Name $VM.Name
}
注意 :移除虚拟机仅移除 VM 对象,不会删除虚拟机磁盘,除非使用 -DeleteVHD 参数。 Import-AzureVM 只是使用导出的虚拟机磁盘创建新的 VM 对象。最后,使用 Import-Azu
超级会员免费看
订阅专栏 解锁全文
86

被折叠的 条评论
为什么被折叠?



