问题是:你能帮我清理一下并添加错误检查吗? 这个脚本中有许多不同的东西,所以这里是详细的顺序: 步骤进行:
以管理员身份运行newsetup.bat
@ECHO OFF
start C:\ClientApps\NewSetup\Scripts\IEBlocker\IEBLOCKALL.bat
start C:\ClientApps\NewSetup\Scripts\RegFiles\Disable_NonAdmins_Installing_Windows_Updates.reg
start C:\ClientApps\NewSetup\Scripts\RegFiles\Disable_UAC.reg
cd %SystemRoot%\system32\WindowsPowerShell\v1.0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start- Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\ClientApps\NewSetup\Scripts\New Setup.ps1""' -Verb RunAs}"
End
在.bat的末尾,它在ps1结束时调用newsetup.ps1,它将重启pc。
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:\ClientApps\NewSetup\Scripts\Pagefile"
$Wupdates = "C:\ClientApps\NewSetup\Scripts\PSWindowsUpdate"
$root = "C:\"
$adobeReader = "C:\ClientApps\NewSetup\Software\AdbeRdr11010_en_US.exe"
$adobeFlash = "c:\ClientApps\NewSetup\Software\install_flash_player_17_active_x.msi"
$adobeAIR = "C:\ClientApps\NewSetup\Software\AdobeAIRInstaller.exe"
$java = "c:\ClientApps\NewSetup\Software\jre1.8.0_40.msi"
$Bloatware = "C:\ClientApps\NewSetup\Software\pc-decrapifier-3.0.0"
$log = "C:\clientapps\NewSetup\Serial&MAC.log"
#Copy/remove & Import Modules
Copy-Item $Wupdates $root -Recurse -Force
Copy-Item $pagefile $root -Recurse -Force
Import-Module C:\Pagefile\pagefile.psm1
Import-Module C:\PSWindowsUPdate\Get-WindowsUpdateConfig.ps1
Import-Module C:\PSWindowsUPdate\Get-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 root\cimv2\TerminalServices).SetAllowTsConnections(1,1) | Out-Null
(Get-WmiObject -Class "Win32_TSGeneralSetting" -Namespace root\cimv2\TerminalServices -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 install。并自动计算虚拟内存。我发现下面的代码我需要检查已安装软件的已安装程序列表。
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
Format-Table –AutoSize
答案 0 :(得分:0)
对于安装所有相关更新的部分,命令行工具WuInstall可能会对您有所帮助,它会通过大量选项自动完成整个更新过程 - 请检查http://www.wuinstall.com