azure - Azure PowerShell Runbook Get Set Az-Disk dynamically
问题描述
The team is trying to automate a snapshot restore, which was achieved successfully. However I am not able to figure out how to dynamically get the previous disk within the resource group; As well as set the next disk with a new name.
In the code below "AZR-001_OsDisk_7" has to set dynamically to "AZR-001_OsDisk_8" the next time it runs:
$diskConfig = New-AzDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy
$disk = New-AzDisk -Disk $diskConfig -ResourceGroupName "ETD-RFT" -DiskName "AZR-001_OsDisk_7"
$disk1 = Get-AzDisk -ResourceGroupName "ETD-RFT" -Name "AZR-001_OsDisk_7"
解决方案
Not a final solution, but I have a quick idea. You may use Get-AzDisk -ResourceGroupName 'ResourceGroupName '
to get all the disks. And then you can get the disk name.
As you named the disk with appropriate rule, you may split the name string by _
, then you will get a string array which contains all the parts. In this way, you will be able to get the version.
A sample:
$disks = Get-AzDisk -ResourceGroupName JackVS2019
foreach($disk in $disks){
$arr = $disk.Name.Split('_')
Write-Host $arr[2]
}
The output:
1
Then you can generate the new disk name.
推荐阅读
- javascript - 需要图像显示在按钮旁边的文本上
- angular - Angular:重新初始化反应形式材料
- c - 在 C http 请求中编辑用户代理
- typescript - 从 TypeScript 声明文件中导出 newable 函数
- apache-spark - 如果不建议将 Cache & Persist 用于 Base RDD(数据帧中的文件加载),那么文件大小大于内存大小的解决方案是什么?
- rust - 如何在为“非默认目标”(如 UEFI)开发的板条箱中执行测试?
- python - Python不会在特定行之后将字符串转换为浮点数
- sql - 带有 integer[] 和另一个数组的 postgresql 搜索列
- java - Spring JmsTemplate 发布资源(IBM 模型队列)
- linux - 系统崩溃后 ZFS 写入顺序问题?