Page 1 of 1

Converting date error

Posted: Mon Jan 23, 2012 3:34 pm
by ITEngineer
Hi All,

Can anyone help me in correcting the following script which cannot display / convert the LastPatchDate please ?
the value sometimes cannot be converted and is like "01cc8accc01c8dc0"

# Create Server List for Patching
$report = @()
foreach($vm in gc C:ListofVMs.txt){
$row = "" | Select Name, State, Status, Host, CPU_Allocated, RAM_Allocated, LastReboot, LastPatchApplied, LastPatchDate, Rebooted, Issues
$row.Name = $vm.Name
$row.State = $vm.PowerState
$row.Status = $vm.ExtensionData.Summary.OverallStatus
$row.Host = $vm.VMHost
$row.CPU_Allocated = $vm.numcpu
$row.RAM_Allocated = $vm.memorymb
$row.LastReboot = [System.Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject win32_operatingsystem -cn $row.Name).lastbootuptime)
$lastPatch = Get-WMIObject Win32_QuickFixEngineering -ComputerName $row.Name |
where {($_.psBase.properties[InstalledOn].Value).Length -gt 0} |
Sort-Object -Property {
if($vm.Guest.GuestId -eq "WinLonghornGuest"){
$_.InstalledOn
}else{
[datetime]($_.psbase.Properties[InstalledOn].Value)
}
} |
Select -Last 1
$row.LastPatchApplied = $lastPatch.HotfixId
if($vm.Guest.GuestId -eq "WinLonghornGuest"){
$row.LastPatchDate = $lastPatch.InstalledOn
}
else{
$row.LastPatchDate = $lastPatch.psbase.Properties[InstalledOn].Value
}
$row.Rebooted = "YES/NO"
$row.Issues = "YES/NO"
$report += $row
}
# Create the Coma Seperated File
$report | Export-Csv C:Patching.csv -NoType


Thanks,

AWT

Converting date error

Posted: Mon Jan 23, 2012 4:14 pm
by ITEngineer
yeah, somehow it doesn't work for some servers but it works for some others.

Converting date error

Posted: Mon Jan 23, 2012 4:40 pm
by jvierra
Here - provethis to yourself. Execute this bit of cde only.

foreach($vm in gc C:ListofVMs.txt){ $vm}

What do you see?

Converting date error

Posted: Mon Jan 23, 2012 4:56 pm
by jvierra
Good for you. Those consultants are just so good.

If you do not have any idea of what you are posting then I suspect you won't understand the answers.

The last patch date is most often not set.

This line makes littel sense:
$lastPatch = Get-WMIObject Win32_QuickFixEngineering -ComputerName $row.Name | where {($_.psBase.properties[InstalledOn].Value).Length -gt 0} | Sort-Object -Property { if($vm.Guest.GuestId -eq "WinLonghornGuest"){ $_.InstalledOn }else{ [datetime]($_.psbase.Properties[InstalledOn].Value) } } | Select -Last 1

What is it trying to do? THe date is a single value. YOu cannot tell what dat that the updates were last run in this way.

Use WU to report the last update time. Or read it fom the windowsupdate.log file