-
Notifications
You must be signed in to change notification settings - Fork 1
/
6-isolate-managed-disks.azcli
27 lines (26 loc) · 1 KB
/
6-isolate-managed-disks.azcli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
###########################################################################################
# Azure CLI Kung-Fu - Blog post
# Dan Patrick - @deltadan
#
#Script Purpose
# - Use listFoo to find Managed Disks in an Unattached state and move them to an different
# resource group.
# **NOTE: this will lock the resource group for other operations while running.
###########################################################################################
az account set -s "subscriptionNameHere"
destRg=destinationResourceGroup
rg=currentResourceGroup
property=diskState
value=Unattached
#load a variable with the list based on the property and value
listFoo=$(az disk list -g $rg \
--query "[?$property=='$value']".id \
-o tsv | sed "s/.*/& /" | tr -d '\n' | rev | cut -c 2- | rev)
# Run loop to update the disks based on array in listFoo
array=($listFoo)
for disks in "${array[@]}"
do
az resource move --destination-group $destRg \
--ids $disks
done