PowerShell 在hyper-v中创建虚拟机

本文介绍了一种使用PowerShell脚本配置Hyper-V虚拟机的方法,适用于50331课程的教学环境搭建。所需环境包括PowerShell 3.0、Windows Server 2012或Windows 8 Pro,且C盘至少有200GB可用空间。脚本创建了运行客户端和服务器操作系统的两个虚拟机,并分配了相应的内存、硬盘大小及网络设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# This script configures the Hyper-V machines used for the 50331 Course.
# PowerShell 3.0 and Windows Server 2012 or Windows 8 Pro are required to perform this setup
# The C:\ Drive should have at least 200GB of free space available.
# All the files on the 50331 Student CD should be copied to C:\Labfiles before performing this setup.
# Variables
$CLI1 = "test_client"        # Name of VM running Client Operating System
$SRV1 = "test_server"        # Name of VM running Server Operating System
$CRAM = 4GB                                # RAM assigned to Client Operating System
$SRAM = 2GB                                # RAM assigned to Server Operating System
$CLI1VHD = 80GB                                # Size of Hard-Drive for Client Operating System
$SRV1VHD = 40GB                                # Size of Hard-Drive for Server Operating System
$VMLOC = "G:\test"                    # Location of the VM and VHDX files
$NetworkSwitch1 = "vlan_out"    # Name of the Network Switch
$W7ISO = "E:\Software\Microsoft\cn_windows_server_2012_r2\cn_windows_server_2012_r2_with_update_x64_dvd_6052725.iso"    # Windows 7 ISO
$W7VFD = "G:\Windows_Server_2012\Virtual Hard Disks\Windows_Server_2012.vhdx"    # Windows 7 Virtual Floppy Disk with autounattend.xml file
$WSISO = "E:\Software\Microsoft\cn_windows_server_2012_r2\cn_windows_server_2012_r2_with_update_x64_dvd_6052725.iso"            # Windows Server 2008 ISO
$WSVFD = "G:\Windows_Server_2012\Virtual Hard Disks\Windows_Server_2012.vhdx"    # Windows Server 2008 Virtual Floppy Disk with autounattend.xml file

# Create VM Folder and Network Switch
MD $VMLOC -ErrorAction SilentlyContinue
$TestSwitch = Get-VMSwitch -Name $NetworkSwitch1 -ErrorAction SilentlyContinue; if ($TestSwitch.Count -EQ 0){New-VMSwitch -Name $NetworkSwitch1 -SwitchType Private}

# Create Virtual Machines
New-VM -Name $CLI1 -Path $VMLOC -MemoryStartupBytes $CRAM -NewVHDPath $VMLOC\$CLI1.vhdx -NewVHDSizeBytes $CLI1VHD -SwitchName $NetworkSwitch1
New-VM -Name $SRV1 -Path $VMLOC -MemoryStartupBytes $SRAM -NewVHDPath $VMLOC\$SRV1.vhdx -NewVHDSizeBytes $SRV1VHD -SwitchName $NetworkSwitch1

# Configure Virtual Machines
Set-VMDvdDrive -VMName $CLI1 -Path $W7ISO
Set-VMDvdDrive -VMName $SRV1 -Path $WSISO
Set-VMFloppyDiskDrive -VMName $CLI1 -Path $W7VFD
Set-VMFloppyDiskDrive -VMName $SRV1 -Path $WSVFD
Start-VM $SRV1
Start-VM $CLI1

 

转载于:https://www.cnblogs.com/wicrecend/p/4931415.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值