2015-04-03 137 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