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
查看全文
相关阅读:
mysql连接数过多 解决方案
单列模式下的数据库连接与Servlet之间页面访问用户登录的小例子
Spring MVC理解和主要使用的注解详解
Spring JDBC 框架中, 绑定 SQL 参数的另一种选择:具名参数(named parameter)
xlwings
openpyxl
【python】Excel两表中某个信息对比
pycharm中配置python版本问题
python指令提示不是内部或外部命令(环境变量配置)
python管理电脑文件及文件夹
原文地址:https://www.cnblogs.com/Liangw/p/2559929.html
最新文章
JAVA设计模式详解(五)----------适配器模式
JAVA设计模式详解(四)----------单例模式
JAVA设计模式详解(三)----------装饰者模式
JAVA设计模式详解(二)----------观察者模式
JAVA设计模式详解(一)----------策略模式
随笔
R语言和深度学习
R是什么
读书的理由
001 简介
热门文章
JFinal事务回滚
html去掉页面滚动条,但保留滚动效果
finereport初体验
datatables实现批量操作
jquery相关内容
js动态删除页面元素
js动态向页面添加元素
开园
简洁美观的Java博客系统Tale开源了,让每一个有故事的人更好的表达想法
Triangles
Copyright © 2011-2022 走看看