Skip to content

Instantly share code, notes, and snippets.

@marckean
Created September 21, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckean/96d9dfdac66c2f92195d12fa63bdb4f6 to your computer and use it in GitHub Desktop.
Save marckean/96d9dfdac66c2f92195d12fa63bdb4f6 to your computer and use it in GitHub Desktop.
$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