zoukankan
html css js c++ java
PowerShell编写小记 之 MiNiTools
运行前 要在PowerShell里运行set-executionpolicy remotesigned
set-executionpolicy remotesigned Start-Sleep -s 2 #激活OS,设定KMS Server到45.234 slmgr.vbs -skms 172.16.45.234 "Set KMS Server..." Start-Sleep -s 5 #判断KMS Server设定是否成功 $title = "The KMS Server" $message = "Set the KMS Server successfully?" $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No" $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) $result = $host.ui.PromptForChoice($title, $message, $options, 0) switch ($result) { 0 { "Get key from KMS Server..." Slmgr.vbs -ato Start-Sleep -s 5 } 1 {"Set KMS server fail"} } #设定UAC到最低 "Set the UAC..." Set-ItemProperty -Path registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system -Name EnableLUA -Value 0 Start-Sleep -s 3 "UAC OK" #设定时区到China "Set the Time Zone..." tzutil /s "China Standard Time" "China Time Zone OK" Start-Sleep -s 2 #设定WUServer到GS的服务器 "Set the WUServer..." #自定义函数检测item function test-value($path,$item) { $item=Get-ItemProperty -Path $path -Name $item -ErrorAction SilentlyContinue return !($item -eq $null) } #自定义注册表赋值函数 function Set-RegistryValue($key, $name, $value) { if ((test-Path $key) -eq $null) {md registry::$key} if (test-value $key $name) {New-ItemProperty $key $name $value} else { Set-ItemProperty registry::$key $name $value } } #判断item是否存在,赋值 Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' 'WUServer' 'http://172.16.104.221' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' 'WUStatusServe' 'http://172.16.104.221' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' 'ElevateNonAdmins' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' 'TargetGroupEnabled' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' 'TargetGroup' '' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'NoAutoUpdate' '00000000' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'AUOptions' '00000004' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'ScheduledInstallDay' '00000000' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'ScheduledInstallTime' '0000000a' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'UseWUServer' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'AutoInstallMinorUpdates' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'RebootRelaunchTimeoutEnabled' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'RebootRelaunchTimeout' '0000000a' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'RescheduleWaitTime' '00000005' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'RescheduleWaitTimeEnabled' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'NoAUShutdownOption' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'NoAUAsDefaultShutdownOption' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'DetectionFrequencyEnabled' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'DetectionFrequency' '00000022' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'NoAutoRebootWithLoggedOnUser' '00000000' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'RebootWarningTimeout' '00000010' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' 'RebootWarningTimeoutEnabled' '00000001' Set-RegistryValue 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 'WSUS Update' 'wuauclt.exe /detectnow' Start-Sleep -s 2 "WUServer OK" #下面绑定Gateway 的Mac地址 "Set the Gateway MAC..." "You can get vaild idx of connection network used from:" netsh i i show in # 据说这个是注释,这个是输入idx的对话框 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Data Entry Form" $objForm.Size = New-Object System.Drawing.Size(300,200) $objForm.StartPosition = "CenterScreen" $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$x=$objTextBox.Text;$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}}) $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,120) $OKButton.Size = New-Object System.Drawing.Size(75,23) $OKButton.Text = "OK" $OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()}) $objForm.Controls.Add($OKButton) $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(150,120) $CancelButton.Size = New-Object System.Drawing.Size(75,23) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(10,20) $objLabel.Size = New-Object System.Drawing.Size(280,30) $objLabel.Text = "Please enter the idx of of network used in the space below(You can get it from powershell screen):" $objForm.Controls.Add($objLabel) $objTextBox = New-Object System.Windows.Forms.TextBox $objTextBox.Location = New-Object System.Drawing.Size(10,70) $objTextBox.Size = New-Object System.Drawing.Size(260,20) $objForm.Controls.Add($objTextBox) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() $x #判断网段 $title = "The Gateway MAC" $message = "Which subnetwork this server in (Now supply 80~83/130~131 only)" $one = New-Object System.Management.Automation.Host.ChoiceDescription "&80~83" $two = New-Object System.Management.Automation.Host.ChoiceDescription "&130~131" $options = [System.Management.Automation.Host.ChoiceDescription[]]($one, $two) $result = $host.ui.PromptForChoice($title, $message, $options, 0) switch ($result) { 0 { netsh -c "i i" add neighbors $x "172.16.83.254" "00-23-89-17-a6-b6" Start-Sleep -s 2 } 1 { netsh -c "i i" add neighbors $x "172.16.131.254" "00-23-89-17-a6-b6" Start-Sleep -s 2 } } "Gateway MAC OK" Start-Sleep -s 2 import-Module ServerManager "Add Server Roles and Features..." Start-Sleep -s 2 "Server will restart..." Start-Sleep -s 3 Add-WindowsFeature Desktop-Experience,GPMC,Web-Server,RDS-RD-Server,Web-Asp-Net,Web-Windows-Auth,Web-Mgmt-Compat -Restart
查看全文
相关阅读:
使用jsonEditor打造一个复杂json编辑器
【原创】一次“诡异”的容器Unix Socket通信问题分析
【原创】Ingress-Nginx-Controller的Metrics监控源码改造简析
IDEA+DevTools实现热部署功能
ElementUI按需引入各种组件
vue-cli4.0更新后怎样将eslint关闭
Mysql修改字段名、修改字段类型
博客搬家CSDN
如何优雅的处理Restful
java系列之注解
原文地址:https://www.cnblogs.com/Liangw/p/2559929.html
最新文章
Hibernate数据库配置文件中数据库名称错误问题
去除oracle中某字段中所有数据的空格(trim函数)
Oracle sql在MyBatis中大于和小于号的转义写法
Docker和k8s的区别与介绍
k8s介绍1
根据系统当年时间查询数据
oracle生成主键唯一的id,函数SYS_GUID()
UNION 和 UNION ALL 操作符
Win10怎么清除最近使用文件 如何关闭常用文件夹
类与方法命名规范,注释,参数标准
热门文章
python slenium jenkins 报错
selenium select方法总结
Mysql 常用语句汇总,表常用操作
Mysql 常用语句汇总,数据库常用操作
selenium之CSS定位汇总
jenkins 构建触发器
jenkins配置qq邮箱
解决:nginx1.17.5+tomcat9 反向代理非80端口导致端口号丢失和403 访问被拒绝问题
记一次排查log4net 不输出日志的解决过程
JSON Editor 中文文档
Copyright © 2011-2022 走看看