-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisknotattached.ps1
33 lines (28 loc) · 904 Bytes
/
disknotattached.ps1
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
28
29
30
31
32
33
$subscriptionNameArray=@("OSTC Shanghai Dev","OSTC Shanghai Test","OSTC Shanghai PM")
[System.Collections.ArrayList]$azureDiskNotAttachedList = @()
Foreach($subscriptionName in $subscriptionNameArray)
{
$existingSubscription = Get-AzureSubscription -SubscriptionName $subscriptionName
if($existingSubscription -eq $null)
{
Clear-AzureProfile -Force
Add-AzureAccount
}
Select-AzureSubscription $subscriptionName
$azureDisks = Get-AzureDisk
Foreach($azureDisk in $azureDisks)
{
if($azureDisk.AttachedTo -eq $null)
{
$azureDiskNotAttachedList.Add($azureDisk.MediaLink.AbsoluteUri)
}
}
}
$output=""
$outputFile="disksnotattached.txt"
Foreach($azureDiskNotAttached in $azureDiskNotAttachedList)
{
$output+=$azureDiskNotAttached
$output+="`r`n"
}
Set-Content -Encoding UTF8 -Path $outputFile -Value $output