Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Abfrage letzte erfolgreiche Installation Windows Update

$
0
0

Guten Morgen ich bin der Werner

Leider bin ich nicht so vertraut mit PowerShell. 

Ich bin auf der Suche nach einer Möglichkeit zu prüfen, wann auf den Rechnern der letzte erfolgreiche Windows Update stattgefunden hat. Die Updates werden über einen WSUS Server verteilt.

Der WSUS ist leider keine sichere Quelle da es durch Kloonen und Provisionieren von Rechnern immer wieder zu doppelten WSUS-ID's gekommen ist und diese Rechner keine Updates bezogen haben.

Also habe ich mich im Internet auf die Suche nach einer Möglichkeit gemacht und ein PowerShell Script gefunden welches soweit auch funktioniert. Leider hat dies nur einen Hacken.... Befindet sich der Rechner (Notebook) im Sleep Modus gibt der Rechner Antwort auf die Ping-Anfrage aber sobald das Script versucht auf die Registry des Rechners zu zugreifen bricht das Script ab. :(

Mein Wunsch wäre es, dass es zwei *.CSV Files gäbe. Eines mit den "Erfolgreichen" Werten und eines mit den "nicht erreichbaren" Rechnern

Mir ist bewusst dass dies nur eine Moment-Aufnahme ist. Aber als Kontrolle und Vergleich dienen könnte.

Besten Dank im Voraus

Hier das Script welches ich wie vorhin erwähnt erweitern oder besser anpassen möchte.

# This script shows the last time that a successful Windows Update was installed. 
# This powershell script needs Quest ActiveRoles Management Shell for Directory which is a free download
# https://software.dell.com/register/71110/

# Clear Screen 
cls 

# Add-PSSSnapin needs to be invoked every time powershell console is restarted
add-PSSnapin quest.activeroles.admanagement 

# Creates an empty array
$OnlineMachines = @() 

# Specify location of the output file/s
$filetxt = "C:\ScriptExport\updateoutput-Virtual.txt"
$filehtml = "C:\ScriptExport\updateoutput-Virtual.htm"

# Retrieve all computer objects in a domain or organizational unit that match the specified condition
# This cmdlet is part of the Quest ActiveRoles Server product
Get-QADComputer -SearchRoot 'domain.ch/clients/Virtual' | %{ 
   
# Win32_PingStatus is a WMI class that represents values returned by standard ping command
# This script is run from Win Server 2003/Win XP; only IPv4 values will be returned
# Stores the result of instances of WMI class based on the WQL statement
$PingResult = Get-WmiObject -Query "SELECT * FROM win32_PingStatus WHERE address='$($_.Name)'" 
   
  # Checks if ping was successful 
  If ($PingResult.StatusCode -eq 0)  
  { 
    # Add the current PC name to the array 
    $OnlineMachines += "$($_.Name)" 
  } 

# Loop through the machines that have returned a successful ping response
foreach ($Machine in $OnlineMachines ) 

    # Specify the registry key 
    $key = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install"
    # Represents the HKEY_LOCAL_MACHINE base key on remote computer
    $keytype = [Microsoft.Win32.RegistryHive]::LocalMachine 
    # Opens a new RegistryKey that represents the requested key on a remote computer
    $RemoteBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$Machine) 
    # Retrieves a subkey as read-only
    $regKey = $RemoteBase.OpenSubKey($key)
    # Retrieves the value associated with the specified name. Returns Nothing if the name/value pair does not exist in the registry
    $KeyValue = $regkey.GetValue("LastSuccessTime") 
    # Establish date format
    $System = (Get-Date -Format "dd-MM-yyyy hh:mm:ss")  
    # Checks for Windows update successful install timestamp against current system time      
    if    ($KeyValue -lt $System) 
    { 
        # Displays output inside the powershell console
# Write-Host $Machine "was last updated on " $KeyValue 

#Writes output to Text file
Write-Output "$($Machine),was last updated on,$($KeyValue)" >> $filetxt
    } 
}

# Next eight lines converts TXT,XLS,CSV to HTML  

# Reads the contents of a text file 
$content = get-content $filetxt 
# Creates an empty array
$contentlines = @()
# Loop through the contents of the text file
Foreach ($line in $content) 
{
# Creates custom COM objects
$value = New-Object -TypeName PSObject
# Adds custom property to the powershell object
Add-Member -InputObject $value -Type NoteProperty -Name Log -Value $line
$contentlines += $value
}
# Converts the contents to CSV format
$contentlines | convertTo-Html -title "Last Update Date" | out-file $filehtml


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>