2015-04-03 130 views
-1

问题是:你们可以帮我清理一下,并添加错误检查? 有配发不同的东西在这个脚本怎么回事所以这里是详细的顺序: 步骤:在的结束新PC安装powershell脚本

  1. 以管理员身份运行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 
    
  2. 。蝙蝠在PS1结束时调用newsetup.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:\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 
    
  3. 我想它做的是加入我想为应用程序来检查应用程序已经安装一个try/catch,然后一个Windows版本检查,如果其Windows 8或8.1运行一第二个.ps1首先调用Win8_apps_removal.ps1脚本,并且不运行adobe flash安装。并自动计算虚拟内存。我发现下面的代码,我觉得将需要检查已安装的软件已安装的程序列表。

    Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | 
    Format-Table –AutoSize 
    
+0

@ChristopherW这问题不是要求进行代码评审,并且不适合[codereview.se]。这可能是这个问题的一个方面,但用户正在寻求帮助来编写其他尚未实现的东西('try' /'catch',检查已安装的应用程序,Windows版本检查,计算虚拟内存等)对于[so],这个问题可能是“太宽泛”了,但对于[codereview.se]来说,这肯定是** off-topic。 – nhgrif 2015-04-04 15:32:40

回答

0

对于安装所有相关的更新的一部分,命令行工具WuInstall可以帮助你相当多,它用大量的选项自动完整的更新过程 - 检查http://www.wuinstall.com

+0

WuInstall完美地工作。那部分讲解员需要任何接触。 – 2015-04-17 20:56:48