Azure 虚拟机 PowerShell 示例Azure Virtual Machine PowerShell samples
下表提供了用于创建和管理 Windows 虚拟机 (VM) 的 PowerShell 脚本示例的链接。The following table provides links to PowerShell script samples that create and manage Windows virtual machines (VMs).
ScriptScript | 说明Description |
---|---|
创建虚拟机Create virtual machines | |
快速创建虚拟机Quickly create a virtual machine | 根据简单的提示创建资源组、虚拟机和所有相关资源。Creates a resource group, a virtual machine, and all related resources, with a minimum of prompts. |
创建完全配置的虚拟机Create a fully configured virtual machine | 创建资源组、虚拟机和所有相关资源。Creates a resource group, a virtual machine, and all related resources. |
创建高度可用的虚拟机Create highly available virtual machines | 使用高度可用且负载均衡的配置创建多个虚拟机。Creates several virtual machines in a highly-available and load-balanced configuration. |
创建 VM 并运行配置脚本Create a VM and run a configuration script | 创建一个虚拟机,并使用 Azure 自定义脚本扩展安装 IIS。Creates a virtual machine and uses the Azure Custom Script extension to install IIS. |
创建 VM 并运行 DSC 配置Create a VM and run a DSC configuration | 创建一个虚拟机,并使用 Azure Desired State Configuration (DSC) 扩展来安装 IIS。Creates a virtual machine and uses the Azure Desired State Configuration (DSC) extension to install IIS. |
上传 VHD 并创建 VMUpload a VHD and create VMs | 将本地 VHD 文件上传到 Azure,从 VHD 创建映像,然后通过该映像创建 VM。Uploads a local VHD file to Azure, creates an image from the VHD, and then creates a VM from that image. |
从托管 OS 磁盘创建 VMCreate a VM from a managed OS disk | 通过将现有托管磁盘附加为 OS 磁盘来创建虚拟机。Creates a virtual machine by attaching an existing Managed Disk as OS disk. |
从快照创建 VMCreate a VM from a snapshot | 通过先从快照创建托管磁盘,然后将新的托管磁盘附加为 OS 磁盘来从快照创建虚拟机。Creates a virtual machine from a snapshot by first creating a managed disk from the snapshot and then attaching the new managed disk as OS disk. |
管理存储Manage storage | |
在相同或不同的订阅中从 VHD 创建托管磁盘Create a managed disk from a VHD in the same or a different subscription | 在相同或不同订阅中,从专用 VHD 将托管磁盘创建为 OS 磁盘,或从数据 VHD 将托管磁盘创建为数据磁盘。Creates a managed disk from a specialized VHD as an OS disk, or from a data VHD as a data disk, in the same or a different subscription. |
从快照创建托管磁盘Create a managed disk from a snapshot | 从快照创建托管磁盘。Creates a managed disk from a snapshot. |
将托管磁盘复制到相同或不同的订阅Copy a managed disk to the same or a different subscription | 将托管磁盘复制到父托管磁盘所在区域中的相同或不同订阅。Copies a managed disk to the same or a different subscription that is in the same region as the parent managed disk. |
将快照作为 VHD 导出到存储帐户Export a snapshot as a VHD to a storage account | 将托管快照作为 VHD 导出到不同区域中的存储帐户。Exports a managed snapshot as a VHD to a storage account in a different region. |
将托管磁盘的 VHD 导出到存储帐户Export the VHD of a managed disk to a storage account | 将托管磁盘的基础 VHD 导出到不同区域的存储帐户。Exports the underlying VHD of a managed disk to a storage account in a different region. |
从 VHD 创建快照Create a snapshot from a VHD | 从 VHD 创建快照,然后使用该快照快速创建多个相同的托管磁盘。Creates a snapshot from a VHD and then uses that snapshot to create multiple identical managed disks quickly. |
将快照复制到相同或不同的订阅Copy a snapshot to the same or a different subscription | 将快照复制到父快照所在区域中的相同或不同订阅。Copies snapshot to the same or a different subscription that is in the same region as the parent snapshot. |
保护虚拟机Secure virtual machines | |
加密 VM 及其数据磁盘Encrypt a VM and its data disks | 创建 Azure Key Vault、加密密钥和服务主体,然后对 VM 进行加密。Creates an Azure key vault, an encryption key, and a service principal, and then encrypts a VM. |
监视虚拟机Monitor virtual machines | |
使用 Azure Monitor 监视 VMMonitor a VM with Azure Monitor | 创建一个虚拟机,安装 Azure Log Analytics 代理,然后在 Log Analytics 工作区中注册该 VM。Creates a virtual machine, installs the Azure Log Analytics agent, and enrolls the VM in a Log Analytics workspace. |
使用 PowerShell 收集订阅中所有 VM 的详细信息Collect details about all VMs in a subscription with PowerShell | 创建一个 csv,其中包含所提供订阅中 VM 的 VM 名称、资源组名称、区域、虚拟网络、子网、专用 IP 地址、OS 类型和公共 IP 地址。Creates a csv that contains the VM Name, Resource Group Name, Region, Virtual Network, Subnet, Private IP Address, OS Type, and Public IP Address of the VMs in the provided subscription. |