troubleshooting Question

Modifying PowerShell script to export to .CSV for the computer within specific OU

Avatar of Senior IT System Engineer
Senior IT System EngineerFlag for Australia asked on
PowershellActive DirectoryScripting Languages
4 Comments2 Solutions69 ViewsLast Modified:
People,

Can anyone here please assist me in modifying the below powershell script so that it can be exported to CSV script for easy sorting ?

# This script shows the last time that a successfull Windows Update was installed.
cls
add-PSSnapin quest.activeroles.admanagement
$OnlineServers = @()

Get-QADComputer -SearchRoot 'domain.com/Terminal Servers/Production 1' -OSName "Windows*Server*" | where {$_.accountisdisabled -eq $false} | % {
  
  $PingResult = Get-WmiObject -Query "SELECT * FROM win32_PingStatus WHERE address='$($_.Name)'"
  
  If ($PingResult.StatusCode -eq 0) {
     # Add the current name to the array
    $OnlineServers += "$($_.Name)"
  }
}

foreach ($Server in $OnlineServers ) {
		$key = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install"
		$keytype = [Microsoft.Win32.RegistryHive]::LocalMachine
		$RemoteBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$Server)
		$regKey = $RemoteBase.OpenSubKey($key)
		$KeyValue = $regkey.GetValue("LastSuccessTime")
	
		$System = (Get-Date -Format "yyyy-MM-dd hh:mm:ss") 
			
		if	($KeyValue -lt $System)	{
			Write-Host " "
			Write-Host $Server "Last time updates were installed was: " $KeyValue
		}
}

Note:

Feel free to replace the Get-QADComputerr with the builtin Get-ADComputerAccount and use Test-Connection instead of the existing convoluted way of doing it.

Ideally the exported result can just be:

ComputerName, last time windows updated, what KBnumber applied if possible.

Thanks in advance,
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros