$subscription = 'Visual Studio Ultimate with MSDN' | |
$username = "powershell@tenant.onmicrosoft.com" | |
$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