forked from fabragaMS/ADPE2E
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADPE2EStop.ps1
56 lines (51 loc) · 1.52 KB
/
ADPE2EStop.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
54
55
56
Workflow Stop-Start-AzureVM
{
Param
(
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
[String]
$AzureSubscriptionId,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]
[String]
$ResourceGroupName,
[Parameter(Mandatory=$true)][ValidateSet("Start","Stop")]
[String]
$Action
)
$credential = Get-AutomationPSCredential -Name 'AzureCredential'
Login-AzureRmAccount -Credential $credential
Select-AzureRmSubscription -SubscriptionId $AzureSubscriptionId
if($AzureVMList -ne "All")
{
$AzureVMs = $AzureVMList.Split(",")
[System.Collections.ArrayList]$AzureVMsToHandle = $AzureVMs
}
else
{
$AzureVMs = (Get-AzureRmVM).Name
[System.Collections.ArrayList]$AzureVMsToHandle = $AzureVMs
}
foreach($AzureVM in $AzureVMsToHandle)
{
if(!(Get-AzureRmVM | ? {$_.Name -eq $AzureVM}))
{
throw " AzureVM : [$AzureVM] - Does not exist! - Check your inputs "
}
}
if($Action -eq "Stop")
{
Write-Output "Stopping VMs";
foreach -parallel ($AzureVM in $AzureVMsToHandle)
{
Get-AzureRmVM | ? {$_.Name -eq $AzureVM} | Stop-AzureRmVM -Force
}
}
else
{
Write-Output "Starting VMs";
foreach -parallel ($AzureVM in $AzureVMsToHandle)
{
Get-AzureRmVM | ? {$_.Name -eq $AzureVM} | Start-AzureRmVM
}
}
}