问题是:你们能帮我清理一下并添加错误检查吗?这个剧本中有很多不同的内容,所以下面是详细的顺序:步骤:
-
以管理员身份运行newsetup.bat
@ECHO OFF start C:ClientAppsNewSetupScriptsIEBlockerIEBLOCKALL.bat start C:ClientAppsNewSetupScriptsRegFilesDisable_NonAdmins_Installing_Windows_Updates.reg start C:ClientAppsNewSetupScriptsRegFilesDisable_UAC.reg cd %SystemRoot%system32WindowsPowerShellv1.0 PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start- Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:ClientAppsNewSetupScriptsNew Setup.ps1""' -Verb RunAs}" End
-
在.bat结束时,它调用newsetup.ps1。在ps1结束时,将重新启动电脑
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { $arguments = "& '" + $myinvocation.mycommand.definition + "'" Start-Process powershell -Verb runAs -ArgumentList $arguments Break } function New-Sleep { [cmdletbinding()] param( [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Mandatory=$true, HelpMessage="No time specified")] [int]$s ) for ($i=1; $i -lt $s; $i++) { [int]$TimeLeft=$s-$i Write-Progress -Activity "Installing Software $s seconds remaining..." -PercentComplete (100/$s*$i) -CurrentOperation "$TimeLeft seconds left ($i elapsed)" -Status "Please wait" Start-Sleep -s 1 } Write-Progress -Completed $true -Status "Please wait" } # end function New-Sleep $pagefile = "C:ClientAppsNewSetupScriptsPagefile" $Wupdates = "C:ClientAppsNewSetupScriptsPSWindowsUpdate" $root = "C:" $adobeReader = "C:ClientAppsNewSetupSoftwareAdbeRdr11010_en_US.exe" $adobeFlash = "c:ClientAppsNewSetupSoftwareinstall_flash_player_17_active_x.msi" $adobeAIR = "C:ClientAppsNewSetupSoftwareAdobeAIRInstaller.exe" $java = "c:ClientAppsNewSetupSoftwarejre1.8.0_40.msi" $Bloatware = "C:ClientAppsNewSetupSoftwarepc-decrapifier-3.0.0" $log = "C:clientappsNewSetupSerial&MAC.log" #Copy/remove & Import Modules Copy-Item $Wupdates $root -Recurse -Force Copy-Item $pagefile $root -Recurse -Force Import-Module C:Pagefilepagefile.psm1 Import-Module C:PSWindowsUPdateGet-WindowsUpdateConfig.ps1 Import-Module C:PSWindowsUPdateGet-WUInstall.ps1 Remove-Item C:Pagefile -Recurse Remove-Item C:PSWindowsUpdate -Recurse #Install Applications &"$adobeAIR" New-Sleep -s 5 &"$adobeReader" /msi EULA_ACCEPT=YES /qn New-Sleep -s 40 msiexec /i "$java" /qb New-Sleep -s 40 msiexec /i "$adobeFlash" /qb #Run Bloatware remover tool & "$Bloatware" #Set Virtual Memory. Set-OSCVirtualMemory -InitialSize 6144 -MaximumSize 12288 -DriveLetter "C:" # Enable Remote Desktop (Get-WmiObject Win32_TerminalServiceSetting -Namespace rootcimv2TerminalServices).SetAllowTsConnections(1,1) | Out-Null (Get-WmiObject -Class "Win32_TSGeneralSetting" -Namespace rootcimv2TerminalServices -Filter "TerminalName='RDP-tcp'").SetUserAuthenticationRequired(0) | Out-Null #Set Power Plan to High Perfermance Try { $HighPerf = powercfg -l | %{if($_.contains("High performance")) {$_.split()[3]}} $CurrPlan = $(powercfg -getactivescheme).split()[3] if ($CurrPlan -ne $HighPerf) {powercfg -setactive $HighPerf} } Catch { Write-Warning -Message "Unable to set power plan to high performance" } #Log Serial & Mac address $ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null $ErrorActionPreference = "Continue" $OutputFileLocation = "$log" Start-Transcript -path $OutputFileLocation -append gwmi win32_bios | fl SerialNumber $mac = Get-WmiObject Win32_NetworkAdapter | Where-Object { $_.MacAddress } | Select-Object Name, MacAddress Get-WmiObject Win32_NetworkAdapter | Where-Object { $_.MacAddress } | Select-Object Name, MacAddress Write-Host "$mac" Stop-Transcript #Change Check for updates to disable Set-WindowsUpdateConfig 1 #start windows updates Write-Host "Looking for Updates...." Get-WUInstall -AcceptAll -AutoReboot
-
我想它要做的是添加一个try/catch,让应用程序检查应用程序是否已经安装,然后检查windows版本,以及它的windows 8或8.1是否运行第二个.ps1,首先调用Win8_apps_removal.ps1脚本,不要运行adobe flash安装。并自动计算虚拟内存。我找到了下面的代码,我觉得这将是检查已安装软件的已安装程序列表所必需的。
Get-ItemProperty HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
对于安装所有相关更新的部分,命令行工具WuInstall可能会对您有所帮助,它通过大量选项自动化了整个更新过程-checkhttp://www.wuinstall.com