powershell 我的Azure VM powershell模块用于管理VM

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 我的Azure VM powershell模块用于管理VM相关的知识,希望对你有一定的参考价值。

function Stop-AZVM($azurecloud,$vmname) 
{ 
    if ($vmname -eq $null) 
    { 
        Get-AzureVM -ServiceName $azurecloud |Foreach-object {Stop-AzureVM -ServiceName $_.ServiceName -Name $_.Name -Force} 
    } 
    else 
    { 
        Stop-AzureVM -ServiceName $azurecloud -Name $vmname 
    } 
}

function Stop-AZSingleVM() 
{ 
    Param(
     [Parameter(Mandatory=$True,Position=1)]
     [string]$VMName
)
    $azuresettings = "C:\Azure\AzureseetingsFile" 
    $azurecloud = "sqltestlab-corpnet"
    Import-AzurePublishSettingsFile $azuresettings

    Stop-AzureVM -ServiceName $azurecloud -Name $VMName 
}

function Start-AZVM($azurecloud,$vmname) 
{ 
    if ($vmname -eq $null) 
    { 
        Get-AzureVM -ServiceName $azurecloud |Foreach-object {Start-AzureVM -ServiceName $_.ServiceName -Name $_.Name -Force} 
    } 
    else 
    { 
        Start-AzureVM -ServiceName $azurecloud -Name $vmname 
    } 
}

function Start-AZSingleVM() 
{ 
    Param(
     [Parameter(Mandatory=$True,Position=1)]
     [string]$VMName
    )
    
    $azuresettings = "C:\Azure\AzureseetingsFile" 
    $azurecloud = "sqltestlab-corpnet"
    Import-AzurePublishSettingsFile $azuresettings

    Start-AzureVM -ServiceName $azurecloud -Name $VMName

}

function Add-AZSQLTestVM() 
{ 
    Param(
     [Parameter(Mandatory=$True,Position=1)]
     [string]$VMName
    )
    
    
    $azuresettings = "C:\Azure\AzureseetingsFile" 
    $azurecloud = "sqltestlab-corpnet" 

    write-host "Importing Azure Settings" 
    Import-AzurePublishSettingsFile $azuresettings

    #had to do this for the storeage account
    Set-AzureSubscription –SubscriptionName "Windows Azure  MSDN - Visual Studio Premium" –CurrentStorageAccount "sqltestlab"

    $vm = Get-AzureVM -ServiceName $azurecloud -Name 'DC1'
    if($vm.PowerState -eq 'Stopped')
        {Start-AzureVM -ServiceName $azurecloud -Name 'DC1'}

    New-AzureVMConfig -Name $VMName -InstanceSize "Medium" -ImageName "STDImage" | Add-AzureProvisioningConfig -WindowsDomain -AdminUsername "MikeNet" –Password "CatDog12" -JoinDomain "corp.contoso.com" -Domain "corp" -DomainUserName "Mike" -DomainPassword "CatDog12"  | New-AzureVM -ServiceName "sqltestlab-corpnet"
}

function Assert-AZVMControl
{
    ################################################################ 
    # Please Change These Variables to Suit Your Environment 
    # 
    $azuresettings = "C:\Azure\AzureseetingsFile" 
    $azurecloud = "sqltestlab-corpnet" 
    # 
    # 
    # 
    ################################################################

    write-host "Importing Azure Settings" 
    Import-AzurePublishSettingsFile $azuresettings

    write-host "Choose the options to Start and Stop your Azure VMS" 
    write-host "1. Start All VMs" 
    write-host "2. Stop All VMs" 
    write-host "3. Start One VM" 
    write-host "4. Stop One VM" 
    $answer = read-host "Please Select Your Choice"

    Switch($answer) 
    { 
        1{ $vmname = $null;Start-AZVM $azurecloud $vmname} 
        2{ $vmname = $null;Stop-AZVM $azurecloud $vmname} 
        3{ $vmname = read-host "Please Enter VM Name";Start-AZVM $azurecloud $vmname} 
        4{ $vmname = read-host "Please Enter VM Name";Stop-AZVM $azurecloud $vmname} 
    }
}
Import-Module C:\Users\mike.SQL01\OneDrive\PSModules\AZVMControl.psm1 -Force -Verbos

以上是关于powershell 我的Azure VM powershell模块用于管理VM的主要内容,如果未能解决你的问题,请参考以下文章

如何使用Powershell脚本获取Azure VM来宾指标(性能计数器)

Azure PowerShell - 虚拟机标记报告

powershell 使用powershell创建用于测试SQL的Azure VM

powershell Azure:检查VM代理运行状况

powershell 调整Azure VM磁盘的大小。

powershell 获取最新的Azure VM