We help IT Professionals succeed at work.
Get Started

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

66 Views
Last Modified: 2016-03-02
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
		}
}

Open in new window


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,
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE