I have the following code that works. It will return the number of days since the last reboot. $machine is a list of machines read from an AD OU.
# this is done within a LOOP
$lastboot = Get-WMIObject -class win32_operatingsystem -ComputerName $machine
$lastboot.ConvertToDateTime($LBoot.LastBootUpTime)
I have tried several different things to highlight my output to Excel.
if ($lastboot -gt "*9*") {
$c.Cells.Item($row, 9).Interior.ColorIndex
$c.Cells.Item($row, 9).Font.ColorIndex = 1 }
$c.Cells.Item($row, 9) = $lastboot
I've tried if ($lastboot -gt "*9*"), if ($lastboot -gt "9"), if ($lastboot -gt 9) and nothing I try will change the Excel cell color.
Now, this works fine:
$lastboot = '100'
if ($lastboot -gt "*9*"){write-host "greater than 9"}
How come it does not work within my LOOP?