2016-02-25 76 views
0

需要关闭Azure订阅中的特定虚拟机。有没有办法,我可以让'Get-AzureVM'PowerShell cmdlet从输入文件读取?我们的订阅中有太多虚拟机。因此,在我们的例子中,通过名称来指定单个机器是很乏味的。 请指教。通过输入文件启动/关闭Azure中的特定虚拟机

+0

获取-AzureVM不会读取文件,但您可以从文件中提取所需内容并将其传送到命令。你有什么尝试? – Cobster

+0

喂Cobster,到目前为止,我尝试了Get-Content,并没有像预期的那样工作。 Get-Content C:\ data \ VMlist.txt | ForEach-Object {Start-AzureVM} – Ram

+1

编辑您的问题并在代码中添加代码,而不是在评论中。 –

回答

0

我在下面的答案中假设您正在使用ASM Azure门户,即使用ASM cmdlet时的较早门户。

如果要启动所有虚拟机在订阅那么你可以使用:

Get-AzureVM | Start-AzureVM 

如果你想开始只有特定的虚拟机,那么你可以使用下面的脚本:

#Declaring the Dictionary object to store VM Names along with their Service names 
$VMList = @{} 

#Adding VMs to the VM List 
#You can replace this section with reading from file and then populating your dictionary object 
#Replace the VM Name and Service name with your environment data 
$VMList.Add("VMName01", "ServiceName") 
$VMList.Add("VMName02","ServiceName") 

#Getting the VM object using Get-AzureVM and then starting the VMs 
$VMList.Keys | % {Get-AzureVM -Name $_ -ServiceName $VMList.Item($_)} | Start-AzureVM