Azure 가상 머신 일괄 켜기/시작

1616 단어 Cloud
$userName = “[YourOrgID]”
$securePassword = ConvertTo-SecureString -String “[Azure Password]” -AsPlainText -Force
$subscriptionName= ‘[YourSubscription]’
$VMNamesArray=’VM01;VM02;VM03’
$ResourceGroupName=’YourResourceGroupName’
cred=New−ObjectSystem.Management.Automation.PSCredential( c r e d = N e w − O b j e c t S y s t e m . M a n a g e m e n t . A u t o m a t i o n . P S C r e d e n t i a l ( userName, $securePassword)
Add-AzureRMAccount -Credential $cred -Environment AzureChinaCloud
Select-AzureRmSubscription -SubscriptionName $subscriptionName | Select-AzureRmSubscription
VMNames= V M N a m e s = VMNamesArray -split “;”
Foreach ( VMNamein V M N a m e i n VMNames) { VM= Get-AzureRMVM | Where-Object {( VM= Get-AzureRMVM | Where-Object {( _.ResourceGroupName -eq ResourceGroupName)−and( R e s o u r c e G r o u p N a m e ) − a n d ( _.Name -eq $VMName)}
if($VM)
{
        "VM Name " + $VM.Name + " is Existing in Resource Group " + $ResourceGroupName

        #Get VM Status
        $vmStatus = (Get-AzureRMVM -ResourceGroupName $VM.ResourceGroupName -Name $VM.Name -Status).Statuses.DisplayStatus[1]

        if($vmStatus -eq 'VM deallocated')
        {
            "Start VM Name " +  $VM.Name
            Start-AzureRMVM -ResourceGroupName  -Name $VM.Name -ResourceGroupName $vm.ResourceGroupName  -Verbose -Force 
        }
}
else
{
    "VM Name " +  $VM.Name + " is NOT Existing in Resource Group " + $ResourceGroupName + " Please check the configuration"
}

}

좋은 웹페이지 즐겨찾기