forked from robotechredmond/Azure-PowerShell-Snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureRM - Start VMs in Parallel.ps1
53 lines (30 loc) · 1.3 KB
/
AzureRM - Start VMs in Parallel.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
51
52
53
workflow Shutdown-Start-ARM-VMs-Parallel {
Param(
[Parameter(Mandatory=$true)]
[String]
$ResourceGroupName,
[Parameter(Mandatory=$true)]
[Boolean]
$Shutdown
)
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
$CredentialAssetName = "DefaultAzureCredential";
#Get the credential with the above name from the Automation Asset store
$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
if(!$Cred) {
Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
}
#Connect to your Azure Account
Add-AzureRmAccount -Credential $Cred
$vms = Get-AzureRmVM -ResourceGroupName $ResourceGroupName;
Foreach -Parallel ( $vm in $vms ) {
if ( $Shutdown ) {
Write-Output "Stopping $($vm.Name)";
Stop-AzureRmVm -Name $vm.Name -ResourceGroupName $ResourceGroupName -Force;
}
else {
Write-Output "Starting $($vm.Name)";
Start-AzureRmVm -Name $vm.Name -ResourceGroupName $ResourceGroupName;
}
}
}