Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1122114
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: PERL

2014-05-08 14:17:26


Windows Azure Powershell Batch scripts

These scripts are using in prodution,and by testing.

点击(此处)折叠或打开

  1. #The virtual machines for each subscription


  1. #The subscription Number.


  1. $AAID = 60..70


  1. #The Subscription'ID  prefix


  1. $MS = "MS-"
  2. foreach ( $n in $AAID )
  3. {
  4. $ID = $MS+$n
  5. Select-AzureSubscription -SubscriptionName $ID
  6. Get-AzureVM
  7. }


  8. #batch remove the subscriptionnames name
  9.  $ID = Get-AzureSubscription|select SubscriptionName
  10.  $ID | Remove-AzureSubscription

  11. #batch shutdown VM
  12. $MSID="Enterprise-30核-10-2","MS-11","Enter-xiaomi"
  13. #$Vname=(100..110)
  14. #$Svname="ftest"
  15. foreach ( $ID in $MSID ) {
  16. #$SV=$Svname+$n
  17. Select-AzureSubscription -SubscriptionName $ID
  18. Get-AzureVM|Stop-AzureVM -StayProvisioned #(The StayProvisioned has VIP when vm was shutdowned.it will be costed)
  19. }

  20. #check the virtual machines status in diffierent subscriptions
  21. $MSID="Enterprise-30核-10-2"
  22. #$Vname=(100..110)
  23. #$Svname="ftest"
  24. foreach ( $ID in $MSID ) {
  25. #$SV=$Svname+$n
  26. Select-AzureSubscription -SubscriptionName $ID
  27. Get-AzureVM
  28. }
       
       #batch delete, reboot, shutdown, down remote RDP files
  1. #The subscription ID name
  2. $AAID = "name"
  3. #save the file name suffix
  4. $RDP = ".rdp"
  5. #the subscription id name prefix
  6. $MS = "MS-"

  7. #Location fo the remote file storages
  8. $DISK = "f:\test\"
  9. foreach ( $n in $AAID ) {
  10.  $ID = $MS+$n

  11.  Select-AzureSubscription -SubscriptionName $ID
  12.   foreach ( $v in (0,1) ) {
  13.   $VM = Get-AzureVM
  14.   $Vname = $VM[$v].Name
  15.   $Sname = $VM[$v].ServiceName
  16.   $DDISK = $DISK+$Vname+$RDP
  17.  #write-host $v
  18.  #write-host $Vname
  19.  #write-host $Sname
  20.  # write-host $DDISK
  21.  ###Please manually, annotation modify the content information, and make the corresponding operation

  1.  #Write-Host "check the subscription' virtual machines,Please wait for a minutes...."
  2.  #Write-Host $ID
  3.  #Get-AzureVM

  4.  #Write-Host "remove the virtual machine, Please wait for a minites..."
  5.  #Remove-AzureVM -ServiceName $Sname -Name $Vname -Verbose

  6.  #Write-Host "remove the cloud server, Please wait for a minites..."
  7.  #Remove-AzureService -ServiceName $Sname -Force

  8.  #Write-Host "Remove all VHD, Please wait....."
  9.  #Get-AzureDisk|select DiskName|Remove-AzureDisk -DeleteVHD
  10.  

  11.   #Write-Host "Reboot the virtual machine, Please wait for a minutes..."
  12.   #Restart-AzureVM -ServiceName $Sname -Name $Vname

  13.   #Write-Host "Shutdown the virtual machine, Plase wait for a minutes..."
  14.   #Stop-AzureVM -ServiceName $Sname -Name $Vname -StayProvisioned  #(The StayProvisioned,the VIP,internet IP will be save when the virtual machines shutdown)
  15.  
  16.   #Write-Host "Down the"$ID" RDP files, Please wait for a minutes..."
  17.   #Get-AzureRemoteDesktopFile -ServiceName $Sname -Name $Vname -LocalPath $DDISK
  18.   }
  19.     }



  20. ##batch down remote RDP files

  21. #The subscription ID name.
  22. $AAID = 100..108
  23. #save file sufix
  24. $RDP = ".rdp"
  25. #The subscription prefix
  26. $MS = "MS-"

  27. #Location of the remote files
  28. $DISK = "f:\test\"
  29. foreach ( $n in $AAID ) {
  30.  $ID = $MS+$n

  31.  Select-AzureSubscription -SubscriptionName $ID
  32.   foreach ( $v in (0,1) ) {
  33.   $VM = Get-AzureVM
  34.   $Vname = $VM[$v].Name
  35.   $Sname = $VM[$v].ServiceName
  36.   $DDISK = $DISK+$Vname+$RDP
  37.  #write-host $v
  38. # write-host $Vname
  39.  #write-host $Sname
  40.  # write-host $DDISK
  41.   
  42.  # $ID
  43. # Get-AzureVM
  44.  Get-AzureRemoteDesktopFile -ServiceName $Sname -Name $Vname -LocalPath $DDISK
  45.   
  46.   }
  47.     }


  48. ##check the virtual machines(Port,DNS,URL etc..)

  49. #the subscription id name
  50. $AAID = "name"
  51. #the subscription id prefix
  52. $MS = ""

  53. foreach ( $n in $AAID ) {
  54.  $ID = $MS+$n
  55.  Select-AzureSubscription -SubscriptionName $n
  56.  #Write-Host "check"$ID" the subscription' virtual machines status"
  57.  #Get-AzureVM |Get-AzureDeployment |select "Name","Url","Status"
  58.  Write-Host "check"$ID" the subscription' virtual machines' IP ,VIP, Port etc..."
  59.  Get-AzureVM |Get-AzureEndpoint |select "Name","Vip","Protocol","Port"

  60.  }


  61. ###import the subscription
  62.  Get-AzurePublishSettingsFile -Environment AzureChinaCloud
  63.  Import-AzurePublishSettingsFile Publish_name(the subscription name)

  64. ###check the subscription names
  65.  Get-AzureSubscription|select SubscriptionName

  66. ######batch create virtual machines in the diffieretion subscription
  67. $MSID = 60..65 #the subscription sufix
  68. $VMNUM = 82..93 #the virtual machines sufix
  69. $MS = "MS-" #the subscription prefix
  70. $STORAGE = "portalwkgbcwfjkdsf" #the storage accout prefix
  71. $location = "China North" #location
  72. $VMSIZE = "Small" #create virtual machine size(ExtaSmall(V0),Small(V1),Medium(V2),Large(V3),
  73. $VNAME = "ftest0" #create virtual machine prefix
  74. $a=0
  75. foreach ( $n in $MSID ) {
  76.  $ID = $MS+$n
  77.  #$SNAME = $VNAME+$m
  78.  #$NSTORAGE = $STORAGE+$SNAME
  79.  $b=$a*2;
  80.  $c=$a*2+1;
  81.  $STORAGE = $VNAME+$VMNUM[$b]

  82.  $Vnm1 = $VMNUM[$b]
  83.  $Vnm2 = $VMNUM[$c]

  84. # Write-Host $ID
  85. # Write-Host $Vnm1
  86. # Write-Host $Vnm2
  87. Select-AzureSubscription -SubscriptionName $ID
  88. New-AzureStorageAccount -StorageAccountName $STORAGE -Location $location

  89. #batch create Linux virtual machines
  90. #<
  91. #$imageName = "f1179221e23b4dbb89e39d70e5bc9e72__OpenLogic-CentOS-65-20140415" #Linux image files
  92. #$Vnm1..$Vnm2|ForEach {New-AzureVMConfig -Name $VNAME$_ -InstanceSize $VMSIZE -ImageName $imageName ` |
  93. #Add-AzureProvisioningConfig -Linux LinuxUser ‘testadmin’ -Password 'Passw0rd' ` |
  94. #Add-AzureEndpoint -Name "Http" -Protocol "tcp" -PublicPort 80 -LocalPort 80 |
  95. #Add-AzureEndpoint -Name "Http" -Protocol "tcp" -PublicPort 21 -LocalPort 21 |
  96. #New-AzureVM -ServiceName $VNAME$_ -Location 'China North'}
  97. #$a++
  98. #>

  99. #batch create Widows virtual machines
  100. $imageName = "55bc2b193643443bb879a78bda516fc8__Win2K8R2SP1-Datacenter-201403.01-zh.cn-127GB.vhd" #Windows image files
  101. $Vnm1..$Vnm2|ForEach {
  102. New-AzureVMConfig -Name $VNAME$_ -InstanceSize $VMSIZE -ImageName $imageName ` |
  103. Add-AzureProvisioningConfig -Windows -AdminUsername ‘testadmin’ -Password 'Passw0rd' ` |
  104. Add-AzureEndpoint -Name "Http" -Protocol "tcp" -PublicPort 80 -LocalPort 80 |
  105. Add-AzureEndpoint -Name "Http" -Protocol "tcp" -PublicPort 21 -LocalPort 21 |
  106. New-AzureVM -ServiceName $VNAME$_ -Location 'China North'
  107.    }

  108. $a++

  109. }



  110. #batch create virtual machines, it's tested

  111. #the subscription id name
  112. $ID = "MS-85"
  113. #the storage account name
  114. $STORAGE = "portalftest148"
  115. #location
  116. $location = "China North"
  117. #Switch the subscription id 
  118. Select-AzureSubscription -SubscriptionName $ID
  119. #create storage account
  120. New-AzureStorageAccount -StorageAccountName $STORAGE -Location $location
  121. #set storage account default
  122. Set-AzureSubscription -SubscriptionName $ID -CurrentStorageAccountName $STORAGE
  123. #set windows 08 images
  124. $imageName = "55bc2b193643443bb879a78bda516fc8__Win2K8R2SP1-Datacenter-201403.01-zh.cn-127GB.vhd"
  125. #create virtual machines
  126. 147..148|ForEach {New-AzureVMConfig -Name ftest$_ -InstanceSize 'Small' -ImageName $imageName ` |
  127. Add-AzureProvisioningConfig –Windows –AdminUsername ‘testadmin’ -Password 'Passw0rd' ` |
  128. Add-AzureEndpoint -Name "Http" -Protocol "tcp" -PublicPort 80 -LocalPort 80 |
  129. New-AzureVM -ServiceName ftest$_ -Location 'China North'}


 
阅读(6472) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~