Rufen Sie uns an
+41 71 508 14 51

Schreiben Sie uns
support@fixthis.ch

Öffnungszeiten
Mo-Fr: 08:00 - 20:00

logo-wide-120

Windows Updates automatisch installieren lassen

Verfasst am: 11. März 2020  |  
Kategorie: ,

Wieso?

Dieses Powershell Skript kann dazu verwendet werden Updates automatisch installieren zu lassen. Wer die Schnauze voll hat immer auf Updates suchen, Updates installieren und jetzt Neustarten zu klicken, der hat bestimmt Freude am Skript

Ich habe das Skript schon länger nicht mehr verwendet. Evtl. enthält es Bugs. Jedoch ist alles dabei was benötigt wird. So könnt ihr ganz einfach euer eigenes Skript zusammen copypasten.

Wie verwenden?

Einfach einen Task machen, der das Skript beim Starten automatisch ausführt. Security-Policy nicht vergessen 😉 set-executionpolicy remotesigned

Das Skript

Windows Auto Update:
$module = Get-Module -Name PSWindowsUpdate

if ($module.Count -ne "1"){
    #Variablen
    $downloadLink = "http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc/file/41459/43/PSWindowsUpdate.zip"
    $tempPath = $env:USERPROFILE+"\Downloads"
    $zipFile = "PSWindowsUpdate.zip"

    $modulePath1=$env:USERPROFILE+"\Documents\WindowsPowerShell\Modules"
    $modulePath2=$env:WINDIR+"\SysWOW64\WindowsPowerShell\v1.0\Modules"

    #Funktionen
    function Expand-ZIPFile($file, $destination){
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($file)
    foreach($item in $zip.items()){
    $shell.Namespace($destination).copyhere($item)
    }
    }

    wget $downloadLink -outfile $tempPath"\PSWindowsUpdate.zip"

    if (Test-Path $($tempPath+'\'+$zipFile)){
    mkdir $tempPath"\PSTools"
    mkdir $tempPath"\PSTools\PSWindowsUpdate"
    Expand-ZIPFile –File ($tempPath+"\PSWindowsUpdate.zip”) –Destination$tempPath"\PSTools"
    }
    else{
    echo Konnte ZIP-File nicht herunterladen!
    }

    #Löschen der heruntergeladenen Daten
    del ($tempPath+"\PSWindowsUpdate.zip”)

    #Kopiere Moduldateien an Bestimmungsort
    if (-Not (Test-Path $($env:USERPROFILE+"\Documents\WindowsPowerShell"))){
    New-Item -Path $env:USERPROFILE"\Documents\WindowsPowerShell" -ItemType directory
    }
    if (-Not (Test-Path $($env:USERPROFILE+"\Documents\WindowsPowerShell\Modules"))){
    New-Item -Path $env:USERPROFILE"\Documents\WindowsPowerShell\Modules" -ItemType directory
    }
    if (-Not (Test-Path $($env:USERPROFILE+"\Documents\WindowsPowerShell\Modules\PSWindowsUpdate"))){
    New-Item -Path $env:USERPROFILE"\Documents\WindowsPowerShell\Modules\PSWindowsUpdate" -ItemType directory
    }

    if (-Not (Test-Path $($modulePath2+"\PSWindowsUpdate"))){
    New-Item -Path $modulePath2"\PSWindowsUpdate" -ItemType directory
    }

    Copy-Item -r ($tempPath+"\PSTools\PSWindowsUpdate\*")($modulePath1+"\PSWindowsUpdate") -passthru | foreach{$_.FullName;$len += ($_.length/1KB);}; Write-Host $len "Bytes kopiert"; $len=0;
    Copy-Item -r ($tempPath+"\PSTools\PSWindowsUpdate\*")($modulePath2+"\PSWindowsUpdate") -passthru | foreach{$_.FullName;$len += ($_.length/1KB);}; Write-Host $len "Bytes kopiert"; $len=0;

    $Error.Clear()
    Import-Module PSWindowsUpdate
    if(!$?){
            echo "Es ist ein Fehler augetreten"
    }
        else{
            echo "OK"
    }
}


# Windows Updates installieren

Get-WUInstall -Acceptall -Autoreboot -Verbose

Wir kümmern uns auch gerne um Ihre Skripts. Kontaktieren Sie uns einfach per E-Mail oder rufen Sie uns an.

crosslist linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram