Created
September 21, 2016 23:57
-
-
Save marckean/96d9dfdac66c2f92195d12fa63bdb4f6 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
$subscription = 'Visual Studio Ultimate with MSDN' | |
$username = "[email protected]" | |
$password = "Password" | |
### Log into Azure with an organisational account | |
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force | |
$Cred = New-Object System.Management.Automation.PSCredential ($username, $secpasswd) | |
Login-AzureRmAccount -Credential $Cred | |
#Choose subscription | |
Select-AzureRmSubscription -SubscriptionName $subscription | |
############################################################################################################### | |
# Sequentially start Azure VMs | |
Get-AzureRmVM | where {$_.Name -match 'playlist'}| %{ | |
echo $_.Name | |
$scriptBlock = { | |
param($Arg0, $Arg1, $Arg2, $Arg3, $Arg4) | |
### Log into Azure with an organisational account | |
$secpasswd = ConvertTo-SecureString $Arg3 -AsPlainText -Force | |
$Cred = New-Object System.Management.Automation.PSCredential ($Arg2, $secpasswd) | |
Login-AzureRmAccount -Credential $Cred | |
#Choose subscription | |
Select-AzureRmSubscription -SubscriptionName $Arg4 | |
Start-AzureRmVM -Name $Arg0 -ResourceGroupName $Arg1 | |
} | |
Start-Job $scriptBlock -ArgumentList @($_.Name, $_.ResourceGroupName, $username, $password, $subscription) | |
} | |
# Wait for it all to complete | |
While (Get-Job -State "Running") | |
{ | |
Start-Sleep 10 | |
echo '---------------------------' | |
Get-Job | |
Get-Job | Receive-Job | |
} | |
Remove-Job * | |
############################################################################################################### | |
# Sequentially stop Azure VMs | |
Get-AzureRmVM | where {$_.Name -match 'playlist'}| %{ | |
echo $_.Name | |
$scriptBlock = { | |
param($Arg0, $Arg1, $Arg2, $Arg3, $Arg4) | |
### Log into Azure with an organisational account | |
$secpasswd = ConvertTo-SecureString $Arg3 -AsPlainText -Force | |
$Cred = New-Object System.Management.Automation.PSCredential ($Arg2, $secpasswd) | |
Login-AzureRmAccount -Credential $Cred | |
#Choose subscription | |
Select-AzureRmSubscription -SubscriptionName $Arg4 | |
Stop-AzureRmVM -Name $Arg0 -ResourceGroupName $Arg1 -Force | |
} | |
Start-Job $scriptBlock -ArgumentList @($_.Name, $_.ResourceGroupName, $username, $password, $subscription) | |
} | |
# Wait for it all to complete | |
While (Get-Job -State "Running") | |
{ | |
Start-Sleep 10 | |
echo '---------------------------' | |
Get-Job | |
Get-Job | Receive-Job | |
} | |
Remove-Job * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment