云桌面-Windows 服务器常规性设置-Powershell 脚本
程序是用PowerShell语言编写的Windows服务器常规性设置工具,可以帮助你快速进行Windows服务器设置。以下是使用说明:
运行程序后,会显示菜单,其中包括了常见的Windows服务器设置选项,比如设置IP地址、设置主机名、计算机加域、计算机退域等。
输入对应的序号即可执行相应的操作,例如输入“1”来设置IP地址。
在执行某些特定操作前,需要输入一些参数,例如在设置IP地址时需要输入主机IP地址。
执行某些操作后,可能需要重启系统或注销当前用户,程序会自动完成这些操作。
如果需要退出程序,可以选择输入“0”或直接关闭程序窗口。
注意,执行某些操作需要管理员权限,因此请在管理员权限下运行此程序。
代码运行效果如下
function input{ cls; Write-Host "windows 服务器常规性设置" -ForegroundColor Yellow write-host '[1] 设置IP地址'; write-host '[2] 设置主机名'; write-host '[3] 计算机加域'; write-host '[4] 计算机退域'; write-host '[5] 计算机重置SID'; write-host '[6] 添加域账号管理员组'; write-host '[7] 计算机挂在网盘'; write-host '[8] 计算机卸载网盘'; write-host '[0] 退出设置'; $choice=read-host '输入你要执行的项目序号(1、2、3、4、5、0)'; switch($choice) { '1' {c1;} '2' {c2;} '3' {c3;} '4' {c4;} '5' {c5;} '6' {c6;} '7' {c7;} '8' {c8;} '0' {c0;} Default {input;} } } function c1{ Write-Host "1、正在设置主机IP地址!" -ForegroundColor Yellow $ip=Read-Host "请输入主机IP地址" $NIC="以太网" netsh interface ip set address name="$NIC" static $ip 255.255.255.0 172.17.13.1 netsh interface ip set dns name="$NIC" static 172.17.13.20 primary netsh interface ip add dns name="$NIC" 172.17.14.20 netsh interface ip add dns name="$NIC" 172.17.15.20 ncpa.cpl reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" /v DisabledComponents /t REG_DWORD /d 0xffffffff /f #reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" /v DisabledComponents /t REG_DWORD /d 0x10 /f #查询IP地址 echo "查询主机IP地址!" ipconfig /all } function c2{ Write-Host "2、正在设置主机名称!" -ForegroundColor Yellow $NewName=Read-Host "请输入主机名称" Rename-Computer -NewName CVAD-SH-$NewName #添加计算机描述 reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters" /v srvcomment /t reg_sz /d $NewName /f #查询主机名称 echo "------------查询主机名称----------------" timeout /nobreak /t 5 sysdm.cpl hostname Restart-Computer } function c3{ Write-Host "3、正在将主机加域中,完成将会重启系统!" -ForegroundColor Yellow $domain = "futurecloud.com" $password = "123.com" | ConvertTo-SecureString -asPlainText -Force $username = "$domain\administrator" $credential = New-Object System.Management.Automation.PSCredential($username,$password) Add-Computer -DomainName $domain -Credential $credential #查询加域状态 wmic computersystem get domain Restart-Computer } function c4{ Write-Host "4、正在退出域! 完成后会重启系统!" -ForegroundColor Yellow echo "请输入Administrator管理账号密码" #Remove-Computer -UnjoinDomaincredential roffice.com.cn\Administrator -PassThru -Verbose -Restart Remove-Computer -ComputerName "localhost" -UnjoinDomainCredential .\sysadmin -WorkgroupName "Workgroup" -Restart -Force } function c5{ Write-Host "5、正在重置计算SID! 完成后会重启系统!" -ForegroundColor Yellow #cd C:\Windows\System32\Sysprep #.\sysprep.exe /generalize /oobe /reboot } function c6{ Write-Host "6、正在添加域账号本地管理员组,成后会注销系统!" -ForegroundColor Yellow net localgroup Administrators /add futurecloud\ctxadmin logoff } function c7{ Write-Host "7、正在挂在网盘! 完成后请使用!" -ForegroundColor Yellow net use P: \\172.17.10.4\iso 123.com /user:administrator reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##172.17.10.4#iso" /v _LabelFromReg /t REG_SZ /d 公共网盘 /f Start P:\ } function c8{ Write-Host "8、正在卸载网盘! 完成后请注销系统!" -ForegroundColor Yellow net use P: /d /yes net session /delete /y } function c0{ Write-Host "0、正在退出Windows设置!" -ForegroundColor Yellow exit } input;