会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Loading
大菜鸟在云端
博客园
首页
新随笔
联系
订阅
管理
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
posted @
2011-12-28 16:36
魍魉_198x
阅读(
452
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部
公告