I am in a super hurry to try and find a way to query all of our Windows 7 computers on the corporate domain, and determine the last time they used Microsoft Office. We are under audit, that needs to be finished tomorrow (yep), and I want to see if we can uninstall Office before paying for licenses we don't need.
I haven't used PowerShell in a while, and frankly this is what I've found since starting on this code last night - i.e. newb. Maybe, there's a much better or easier way? I tried searching last night for a pre-done script or program, but couldn't find anything that says when Office was last used.
I can get the latest 'LastUse' using the below code and function, but I need to know which computer name that number is associated with. Right now it just returns the latest number: 20170928
function Measure-Latest {
BEGIN { $latest = $null }
PROCESS {
if (($_ -ne $null) -and (($latest -eq $null) -or ($_ -gt $latest))) {
$latest = $_
}
}
END { $latest }
}
$Software = Get-WmiObject -Class win32_softwarefeature | Select Caption,LastUse
$ComputerName = $env:COMPUTERNAME
$(foreach ($item in $Software)
{
$Name = $Item.Caption
$LastUsedString = $Item.Lastuse.Substring(0,8)
$LastUsed = [int]$LastUsedString
if ($Name -like 'Microsoft Office*' -or $Name -like 'Microsoft Outlook')
{
$LastUsed
} }) | Measure-Latest