Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. $subscription = 'Visual Studio Ultimate with MSDN'
  2. $username = "powershell@tenant.onmicrosoft.com"
  3. $password = "Password"
  4.  
  5. ### Log into Azure with an organisational account
  6. $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
  7. $Cred = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
  8. Login-AzureRmAccount -Credential $Cred
  9.  
  10. #Choose subscription
  11. Select-AzureRmSubscription -SubscriptionName $subscription
  12.  
  13. ###############################################################################################################
  14.  
  15. # Sequentially start Azure VMs
  16. Get-AzureRmVM | where {$_.Name -match 'playlist'}| %{
  17. echo $_.Name
  18.  
  19. $scriptBlock = {
  20. param($Arg0, $Arg1, $Arg2, $Arg3, $Arg4)
  21.  
  22. ### Log into Azure with an organisational account
  23. $secpasswd = ConvertTo-SecureString $Arg3 -AsPlainText -Force
  24. $Cred = New-Object System.Management.Automation.PSCredential ($Arg2, $secpasswd)
  25. Login-AzureRmAccount -Credential $Cred
  26.  
  27. #Choose subscription
  28. Select-AzureRmSubscription -SubscriptionName $Arg4
  29.  
  30. Start-AzureRmVM -Name $Arg0 -ResourceGroupName $Arg1
  31. }
  32.  
  33. Start-Job $scriptBlock -ArgumentList @($_.Name, $_.ResourceGroupName, $username, $password, $subscription)
  34. }
  35.  
  36. # Wait for it all to complete
  37. While (Get-Job -State "Running")
  38. {
  39. Start-Sleep 10
  40. echo '---------------------------'
  41. Get-Job
  42. Get-Job | Receive-Job
  43. }
  44.  
  45. Remove-Job *
  46.  
  47. ###############################################################################################################
  48.  
  49. # Sequentially stop Azure VMs
  50. Get-AzureRmVM | where {$_.Name -match 'playlist'}| %{
  51. echo $_.Name
  52.  
  53. $scriptBlock = {
  54. param($Arg0, $Arg1, $Arg2, $Arg3, $Arg4)
  55.  
  56. ### Log into Azure with an organisational account
  57. $secpasswd = ConvertTo-SecureString $Arg3 -AsPlainText -Force
  58. $Cred = New-Object System.Management.Automation.PSCredential ($Arg2, $secpasswd)
  59. Login-AzureRmAccount -Credential $Cred
  60.  
  61. #Choose subscription
  62. Select-AzureRmSubscription -SubscriptionName $Arg4
  63.  
  64. Stop-AzureRmVM -Name $Arg0 -ResourceGroupName $Arg1 -Force
  65. }
  66.  
  67. Start-Job $scriptBlock -ArgumentList @($_.Name, $_.ResourceGroupName, $username, $password, $subscription)
  68. }
  69.  
  70. # Wait for it all to complete
  71. While (Get-Job -State "Running")
  72. {
  73. Start-Sleep 10
  74. echo '---------------------------'
  75. Get-Job
  76. Get-Job | Receive-Job
  77. }
  78.  
  79. Remove-Job *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement