-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachineretention.ps1
50 lines (39 loc) · 1.09 KB
/
machineretention.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$subscriptionNameArray=@("OSTC Shanghai Dev","OSTC Shanghai Test","OSTC Shanghai PM")
[System.Collections.ArrayList]$largeVMs = @()
[System.Collections.ArrayList]$mediumVMs = @()
Foreach($subscriptionName in $subscriptionNameArray)
{
$existingSubscription = Get-AzureSubscription -SubscriptionName $subscriptionName
if($existingSubscription -eq $null)
{
Clear-AzureProfile -Force
Add-AzureAccount
}
Select-AzureSubscription $subscriptionName
$azureVMs = Get-AzureVM
Foreach($azureVM in $azureVMs)
{
if($azureVM.InstanceSize -eq "Large"){
$largeVMs.Add($azureVM)
}
if($azureVM.InstanceSize -eq "Medium"){
$mediumVMs.Add($azureVM)
}
}
}
$output=""
$outputFile="largevms.txt"
Foreach($largeVM in $largeVMs)
{
$output+=$largeVM.Name
$output+="`r`n"
}
Set-Content -Encoding UTF8 -Path $outputFile -Value $output
$output=""
$outputFile="mediumvms.txt"
Foreach($mediumVM in $mediumVMs)
{
$output+=$mediumVM.Name
$output+="`n"
}
Set-Content -Encoding UTF8 -Path $outputFile -Value $output