在上一篇文章《PowerShell批量导出Azure中的磁盘镜像到存储账户 》中,我们已经把主站点的虚拟机磁盘镜像导出到了灾备站点的存储账户中。本文中我们来演示如何批量基于存储账户Blob中的VHD创建托管磁盘。直接贴脚本吧:
$diskConfig = Get-Content .\vm-disk.config.json -Raw | ConvertFrom-Json $sb = { param($cfg) $vhdUrl = "https://存储账户名称.blob.core.chinacloudapi.cn/容器名称/$($cfg.ImageId).vhd" $diskCfg = New-AzureRmDiskConfig ` -Location "chinaeast2" ` -CreateOption Import ` -SourceUri $vhdUrl ` -SkuName 'Standard_LRS' ` -Confirm:$false Write-Output "正在创建 磁盘 $($cfg.Name) ..." $targetDisk = New-AzureRmDisk ` -ResourceGroupName 'SH2-SAP-POC' ` -DiskName $cfg.Name ` -Disk $diskCfg ` -Confirm:$false Write-Output "磁盘 $($cfg.Name) 已创建." } $jobs = @() foreach ($cfg in $diskConfig) { $job=[PowerShell]::Create() $job = $job.AddScript($sb); $job = $job.AddParameter("cfg",$cfg) Write-Output "创建磁盘【$($cfg.Name)】的Job已开始..." $jobs += New-Object PSObject -Property @{ cfg = $cfg Task = $job Result = $job.BeginInvoke() } } ForEach ($job in $jobs) { $job.Task.EndInvoke($job.Result) }
经测试,15块磁盘只需1分多钟即可创建完成。。
本文链接: https://www.pstips.net/create-azure-managed-disk-based-on-vhd.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!