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

转载于:https://www.cnblogs.com/Liangw/archive/2011/12/28/2559929.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值