Added ShutDownVMsInRescourceGroup.ps1

This commit is contained in:
martinpf 2016-07-15 18:17:51 -07:00
Родитель b87190adf5
Коммит dae69bc7dd
1 изменённых файлов: 35 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,35 @@
Param(
[string] [Parameter(Mandatory=$true)] $SubscriptionId,
[string] [Parameter(Mandatory=$true)] $ResourceGroupName
)
$currentSubscription = (Get-AzureRmContext).Subscription
if ($currentSubscription.SubscriptionId -ne $SubscriptionId)
{
Write-Host "Setting current subscription"
Select-AzureRmSubscription -SubscriptionID $SubscriptionId
}
$vmList = Get-AzureRmVM -ResourceGroupName $ResourceGroupName
if ( -not $vmList -or $vmList.Count -le 0)
{
Write-Host "Error: No VMs were found for the Resource Group: $ResourceGroupName"
return
}
Write-Host ""
Write-Host "Discovered the following VMs in ResourceGroup $ResourceGroupName"
foreach ($vm in $vmList)
{
Write-Host $vm.Name
}
Write-Host ""
foreach ($vm in $vmList)
{
Write-Host Stopping $vm.Name
Stop-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $vm.Name -Force
}