Last active
April 6, 2018 20:44
-
-
Save haray-isao/eebd4a64e3c2101611bc43cf0f47b93f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
workflow Stop-Start-AzureVM2 | |
{ | |
Param | |
( | |
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] | |
[String] | |
$credentialName, | |
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] | |
[String] | |
$ResourceGroup, | |
[Parameter(Mandatory=$true)][ValidateSet("Start","Stop")] | |
[String] | |
$Action | |
) | |
$credential = Get-AutomationPSCredential -Name $credentialName | |
$tennantId = Get-AutomationVariable -Name 'tennantId' | |
Login-AzureRmAccount -Credential $credential -Tenantid $tennantId -ServicePrincipal | |
$AzureVMs = Get-AzureRmVM -ResourceGroup $ResourceGroup | |
if($Action -eq "Stop") | |
{ | |
Write-Output "Stopping VMs"; | |
foreach -parallel ($AzureVM in $AzureVMs) | |
{ | |
$AzureVM | Stop-AzureRmVM -Force | |
} | |
} | |
else | |
{ | |
Write-Output "Starting VMs"; | |
foreach -parallel ($AzureVM in $AzureVMs) | |
{ | |
$AzureVM | Start-AzureRmVM | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment