Powershellisfun终极技巧:5分钟创建Hyper-V评估版Windows Server虚拟机 Powershellisfun终极技巧5分钟创建Hyper-V评估版Windows Server虚拟机【免费下载链接】PowershellisfunRepository with the scripts that I have used in my blogs on https://powershellisfun.com. If you like these, please sponsor this project using the Sponsor button below or buy me a coffee :) https://www.buymeacoffee.com/powershellisfun项目地址: https://gitcode.com/gh_mirrors/po/Powershellisfun想快速搭建Windows Server测试环境Powershellisfun项目提供了一个强大的PowerShell脚本能帮助你在5分钟内自动创建运行评估版Windows Server的Hyper-V虚拟机。这个脚本不仅简化了虚拟机创建流程还能自动下载微软官方评估版VHD文件让测试和学习变得前所未有的简单。 准备工作确认Hyper-V已安装在开始之前确保你的系统已安装Hyper-V角色。脚本会自动检测Hyper-V是否可用# 脚本内置的Hyper-V检测代码 if ((Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online).State -ne Enabled) { Write-Warning (Hyper-V Role and/or required PowerShell module is not installed, please install before running this script...) return }如果尚未安装Hyper-V可以通过以下命令启用需要管理员权限Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All 获取脚本Clone项目仓库首先将Powershellisfun项目克隆到本地git clone https://gitcode.com/gh_mirrors/po/Powershellisfun创建Hyper-V评估版虚拟机的核心脚本位于Create A Hyper-V Running Evaluation Versions Of Windows Server/Create_Eval_Hyper_V_VM.ps1⚡ 一键创建运行脚本的3个简单步骤步骤1启动脚本以管理员身份运行PowerShell导航到脚本所在目录执行.\Create_Eval_Hyper_V_VM.ps1步骤2选择Windows Server版本脚本会自动从微软评估中心获取可用的Windows Server版本列表包括2012 R2、2019、2022和2025并显示一个图形界面让你选择# 脚本自动获取微软评估中心下载链接 $urls ( https://www.microsoft.com/en-us/evalcenter/download-windows-server-2012-r2, https://www.microsoft.com/en-us/evalcenter/download-windows-server-2019, https://www.microsoft.com/en-us/evalcenter/download-windows-server-2022, https://www.microsoft.com/en-us/evalcenter/download-windows-server-2025 )步骤3配置虚拟机参数根据提示输入虚拟机名称、CPU核心数、内存大小并选择网络交换机$VMname Read-Host Please enter the name of the VM to be created, for example W2K22SRV $VMCores Read-Host Please enter the amount of cores, for example 2 [int64]$VMRAM 1GB * (Read-Host Enter Maximum Memory in Gbs, for example 4) 脚本幕后工作原理这个强大的脚本会自动完成以下任务检测Hyper-V环境确保系统满足运行条件获取评估版VHD从微软官方网站下载最新的Windows Server评估版VHD文件创建虚拟机自动配置CPU、内存、磁盘和网络优化设置启用集成服务、设置动态内存、禁用自动检查点# 脚本自动配置虚拟机 Set-VM -Name $VMname -ProcessorCount $VMCores -DynamicMemory -MemoryMinimumBytes 64MB -MemoryMaximumBytes $VMRAM -MemoryStartupBytes 512MB -CheckpointType ProductionOnly -AutomaticCheckpointsEnabled:$false Enable-VMIntegrationService -VMName $VMname -Name Guest Service Interface , Heartbeat, Key-Value Pair Exchange, Shutdown, Time Synchronization, VSS 完成时间统计脚本内置计时器会显示整个部署过程花费的时间# 脚本中的计时器功能 $stopwatch [System.Diagnostics.Stopwatch]::StartNew() # ...部署过程... $stopwatch.Stop() Write-Host (Done, the deployment took {0} hours, {1} minutes and {2} seconds -f $stopwatch.Elapsed.Hours, $stopwatch.Elapsed.Minutes, $stopwatch.Elapsed.Seconds) -ForegroundColor Green 扩展技巧管理和优化你的Hyper-V虚拟机创建虚拟机后你可能还需要压缩VHDX文件使用Compact Hyper-V VHDX files/Compact-VHDX.ps1脚本优化磁盘空间批量更新虚拟机通过Windows Update all Hyper-V VMs/Start-WindowsUpdate-HyperV-VMs.ps1为所有VM安装更新配置网络使用Set Correct External Hyper-V Adapter/Set-CorrectHyperVExternalSwitchAdapter.ps1确保网络连接正常 总结Powershellisfun项目的Create_Eval_Hyper_V_VM.ps1脚本为IT专业人员和学习者提供了一个快速、可靠的方式来创建Windows Server测试环境。通过自动化下载、配置和优化过程你可以在几分钟内拥有一个功能齐全的服务器虚拟机让你专注于学习和测试而不是繁琐的环境搭建。无论是学习新的Windows Server功能还是测试应用兼容性这个工具都能大大提高你的工作效率。立即尝试体验PowerShell自动化带来的便利【免费下载链接】PowershellisfunRepository with the scripts that I have used in my blogs on https://powershellisfun.com. If you like these, please sponsor this project using the Sponsor button below or buy me a coffee :) https://www.buymeacoffee.com/powershellisfun项目地址: https://gitcode.com/gh_mirrors/po/Powershellisfun创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考