1. 程式人生 > >Windows 上安裝 Azure PowerShell及Azure PowerShell部署虛擬機

Windows 上安裝 Azure PowerShell及Azure PowerShell部署虛擬機

net doc ORC fec end 密碼 har 公網 mst

一、Azure PowerShell部署 1、使用 PowerShellGet 在 Windows 上安裝 Azure PowerShell 從 Azure PowerShell 版本 6.0 開始,Azure PowerShell 需要 PowerShell 版本 5.0。 若要查看在計算機上運行的 PowerShell 的版本,運行以下命令: #$PSVersionTable.PSVersion 2、Windows PowerShell升級 https://docs.microsoft.com/zh-cn/powershell/scripting/setup/installing-windows-powershell?view=powershell-6#upgrading-existing-windows-powershell

技術分享圖片

//根據windows版本下載對應的powershell升級補丁 3、開始使用Azure powershell
PS C:\Users\Administrator> Install-Module -Name AzureRM
需要使用 NuGet 提供程序來繼續操作
PowerShellGet 需要使用 NuGet 提供程序“2.8.5.201”或更高版本來與基於 NuGet 的存儲庫交互。必須在“C:\Program
Files\PackageManagement\ProviderAssemblies”或“C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAs
es”中提供 NuGet 提供程序。也可以通過運行 ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force‘
NuGet 提供程序。是否要讓 PowerShellGet 立即安裝並導入 NuGet 提供程序?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
不受信任的存儲庫
你正在從不受信任的存儲庫安裝模塊。如果你信任該存儲庫,請通過運行 Set-PSRepository cmdlet 更改其 InstallationPolic
值。是否確實要從“PSGallery”安裝模塊?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
PS C:\Users\Administrator>
PS C:\Users\Administrator> Login-AzureRmAccount -EnvironmentName AzureChinaCloud     //登錄中國Azure
Account          : ***@XXX.partner.onmschina.cn
SubscriptionName : Windows Azure 企業 c571e67f
SubscriptionId   : ***********************************
TenantId         : ***********************************
Environment      : AzureChinaCloud
二、虛擬機安裝 1、創建資源組 PS C:\Users\Administrator> New-AzureRmResourceGroup -Name lgp2 -Location ChinaEast ResourceGroupName : lgp2 Location : chinaeast ProvisioningState : Succeeded Tags : ResourceId : /subscriptions/c571e67f-785f-4dd6-8cd6-24de40a3812b/resourceGroups/lgp2 2、創建虛擬機 使用 New-AzureRmVM 創建 VM。 請提供每個資源的名稱,如果這些資源不存在,New-AzureRmVM cmdlet 會創建它們。 //出現提示時,提供用作 VM 登錄憑據的用戶名和密碼: PS C:\Users\Administrator> New-AzureRmVm ` >> -ResourceGroupName "lgp2" ` >> -Name "myVM" ` >> -Location "China East" ` >> -VirtualNetworkName "myVnet" ` >> -SubnetName "mySubnet" ` >> -SecurityGroupName "myNetworkSecurityGroup" ` >> -PublicIpAddressName "myPublicIpAddress" ` >> -OpenPorts 80,3389 >> //虛擬機創建成功的系統信息 ResourceGroupName : lgp2 Id : /subscriptions/c571e67f-785f-4dd6-8cd6-24de40a3812b/resourceGroups/lgp2/providers/Microsoft. Compute/virtualMachines/myVM VmId : c4dd1ef3-cf2d-47f3-939b-fec3f9f27f73 Name : myVM Type : Microsoft.Compute/virtualMachines Location : chinaeast Tags : {} HardwareProfile : {VmSize} NetworkProfile : {NetworkInterfaces} OSProfile : {ComputerName, AdminUsername, WindowsConfiguration, Secrets} ProvisioningState : Succeeded StorageProfile : {ImageReference, OsDisk, DataDisks} FullyQualifiedDomainName : myvm-6e4097.China East.cloudapp.azure.com PS C:\Users\Administrator> Get-AzureRmPublicIpAddress -ResourceGroupName "lgp2"|select "ipaddress" 3、遠程到虛擬機 //虛擬機公網IP地址信息 IpAddress --------- 139.219.134.125 //遠程到虛擬機 PS C:\Users\Administrator> mstsc /v:139.219.134.125 //虛擬機部署IIS服務 PS C:\Users\cyberadmin> Install-WindowsFeature -name Web-Server -IncludeManagementTools Success Restart Needed Exit Code Feature Result ------- -------------- --------- -------------- True No Success {Common HTTP Features, Default Document, D... 4、刪除所有相關虛擬資源 PS C:\Users\Administrator> Remove-AzureRmResourceGroup -Name lgp2 Confirm Are you sure you want to remove resource group ‘lgp2‘ [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y True

  

Windows 上安裝 Azure PowerShell及Azure PowerShell部署虛擬機