through the course of our Azure tenant history alot of vm's have been removed, with that said i know we have never removed nics, or managed disks. So i came across this script and don't want to delete just yet but want to view a list of unattached nics and got a few errors and seeing if someone could help please.
# Set deleteUnattachedNics=1 if you want to delete unattached NICs
deleteUnattachedNics=0
unattachedNicsIds=$(az network nic list --query '[?virtualMachine==`null`].[id]' -o tsv)
for id in ${unattachedNicsIds[@]}
do
if (( $deleteUnattachedNics == 1 ))
then
echo "Deleting unattached NIC with Id: "$id
az network nic delete --ids $id
echo "Deleted unattached NIC with Id: "$id
else
echo $id
fi
done
My errors:
At line:4 char:4+ for id in ${unattachedNicsIds[@]}
+ ~
Missing opening '(' after keyword 'for'.
At line:5 char:3
+ do
+ ~
Missing statement body in do loop.
At line:6 char:38
+ if (( $deleteUnattachedNics == 1 ))
+ ~
Missing statement block after if ( condition ).
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword