通过计划任务,Powershell自动切换订阅账户,并自动创建储存账户、虚机,下载RDP文件。
首先,设置powershell执行权限
set-executionpolicy -executionpolicy unrestricted
其次,把下面内容改成
createvm1.ps1文件
-
#订阅ID号
-
$ID = "MS-11"
-
#储存账户
-
$STORAGE = "portalqqmiaosha00"
-
#位置
-
$location = "China North"
-
$a = 0
-
foreach ( $Stnu in (5..6)) {
-
$STname = $STORAGE+$Stnu
-
-
$b = $a*20+1
-
$c = $a*20+19
-
-
#切换到该ID订阅下
-
Select-AzureSubscription -SubscriptionName $ID
-
#创建储存账户
-
Write-Host "The Storage name is $STname"
-
-
#Write-Host "The a $a"
-
#Write-Host "The b $b"
-
#Write-Host "The c $c"
-
-
New-AzureStorageAccount -StorageAccountName $STname -Location $location
-
#设置默认储存账户
-
Set-AzureSubscription -SubscriptionName $ID -CurrentStorageAccountName $STname
-
#设置镜像
-
$imageName = "55bc2b193643443bb879a78bda516fc8__Win2K8R2SP1-Datacenter-201403.01-zh.cn-127GB.vhd"
-
-
-
#创建虚机
-
-
$b..$c|ForEach {New-AzureVMConfig -Name miaosha0$_ -InstanceSize 'Small' -ImageName $imageName ` |
-
Add-AzureProvisioningConfig –Windows –AdminUsername ‘testadmin’ -Password 'Passw0rd' ` |
-
Add-AzureEndpoint -Name "Http" -Protocol "tcp" -PublicPort 80 -LocalPort 80 ` |
-
New-AzureVM -ServiceName miaosha0$_ -Location 'China North'}
-
-
Write-Host "The rdp is downing...."
-
-
foreach ($v in ($b..$c)) {
-
Get-AzureRemoteDesktopFile -ServiceName miaosha0$v -Name miaosha0$v -LocalPath C:\rdp\frdp\miaosha0$v.rdp
-
}
-
-
$a++
-
-
}
然后:编辑setch.bat文件
-
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoExit -ExecutionPolicy Bypass -File c:\rdp\script\createvm1.ps1
-
-
cmd
最后,在win08系统中,打开计划任务,添加计划任务并把该文件添加上
阅读(2182) | 评论(0) | 转发(0) |