Windows Server 2016 & 2019 工作站速配脚本
之前有一篇关于把Windows Server打造成工作站系统的随笔,其中的步骤完全基于手工操作,一部分对系统不熟悉的朋友恐怕会找不到设置的入口。与其弄一堆截图写所谓的教程,还不如写一个程序来自动化处理。
init.ps1
Write-Host "`n正在启用声音服务" Set-Service -Name "Audiosrv" -Status running -StartupType automatic Write-Host "`n禁用登陆前Ctrl+Alt+Del组合键" $regPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System" Remove-ItemProperty -Path $regPath -Name 'DisableCAD' -Force; New-ItemProperty -Path $regPath -Name 'DisableCAD' -Value 1 -PropertyType DWORD -Force; $regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" $owner = (Get-ItemProperty -Path $regPath -Name 'RegisteredOwner').RegisteredOwner Write-Host "本机所有者为: '$owner'" $ans = Read-Host "需要修改所有者吗? [y/N] " if ($ans -eq 'y') { $newOwner = Read-Host -Prompt '请输入新的所有者' Set-ItemProperty -Path $regPath -Name 'RegisteredOwner' -Value $newOwner } # $org = (Get-ItemProperty -Path $regPath -Name 'RegisteredOrganization').RegisteredOrganization Write-Host "`n禁用强制性的密码强度要求" secedit /export /cfg c:\secpol.cfg; (gc C:\secpol.cfg).replace("PasswordComplexity = 1", "PasswordComplexity = 0") | Out-File C:\secpol.cfg; secedit /configure /db c:\windows\security\local.sdb /cfg c:\secpol.cfg /areas SECURITYPOLICY; rm -force c:\secpol.cfg -confirm:$false; $user = $Env:username $ans = Read-Host "`n密码策略已修改,是否需要修改当前密码 [y/N]" if ($ans -eq 'y') { $p1 = Read-Host "请输入新密码" -AsSecureString $p1_txt = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($p1)) $p2 = Read-Host "请再次输入新密码" -AsSecureString $p2_txt = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($p2)) if ($p1_txt.compareTo($p2_txt) -eq 0) { $Account = Get-LocalUser -Name $user $Account | Set-LocalUser -Password $p1 } else { Write-Host "两次输入的密码不一致,密码未修改" } } $ans = Read-Host "当前登陆用户名为:$user,需要修改当前用户名吗 [y/N]" if ($ans -eq 'y') { $nuser = Read-Host "请输入新的用户名" if ($nuser -eq '') { Write-Host '用户名无效' } else { Rename-LocalUser -Name $user -NewName $nuser } } Write-Host "`n正在设置内存面页压缩" $mc = Get-MMAgent if ( -Not($mc.MemoryCompression)) { Enable-MMAgent -MemoryCompression } Write-Host "`n禁止关机事件跟踪器" if ( -Not (Test-Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Reliability')) { New-Item -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT' -Name Reliability -Force } # add registry setting Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Reliability' -Name ShutdownReasonOn -Value 0 Write-Host "`n请在打开的对话框中选择‘仅为基本 Windows 程序和服务启用 DEP’" Start-Process SystemPropertiesDataExecutionPrevention -Wait Write-Host "`n请在打开的对话框中选择‘调整为最佳外观’, 在‘高级’选项卡中选择 调整以优化性能‘程序’" Start-Process SystemPropertiesPerformance -Wait
上面的内容保存为 init.ps1
,可以尝试以管理员权限直接运行,如果运行成功,后面的步骤可以跳过。
如果你通过下载获得此脚本,系统大概率会阻止你运行。此时,要么修改系统的脚本运行策略,要么参考前一篇随笔, 把run.bat
的内容保存在相同目录下面,通过管理员权限运行run.bat
脚本,输入上面的脚本文件名init.ps1
去执行脚本。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂