Script to get Computer name & office version from remote PC's on domain

O'Connor, Tim 21 Reputation points
2021-10-05T02:51:24.247+00:00

Hello All,

I apologize I'm learning PoSH scripts on the fly. I believe the loop is working correctly but I am using Get-WMIObject wrong because I get the error: Get-WMIObject : Invalid query "select machine name here from Win32_Product where Name like '%office%'" InvalidArgument: (:) [Get-WmiObject], ManagementException.

Any help would be much appreciated!

$Adcomp = (get-adcomputer -Filter * -SearchBase "directory here") | Select-Object -ExpandProperty Name
$Results = ForEach ($Computer in $Adcomp) {
$Name = $Computer.Name
$bios = Get-WmiObject Win32_Bios -ComputerName $Computer
$version = Get-WMIObject -Computername $Computer Win32_Product -Filter "Name like '%office%'" $Computer
}
$Results | export-csv C:\test.csv -NoTypeInformation -Append

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,382 questions
{count} votes

Accepted answer
  1. Limitless Technology 39,376 Reputation points
    2021-10-05T10:27:38.083+00:00

    Hi there,

    To find office components installed use this WMI method:

    Get-Content -Path c:\scripts\Computers.txt |
    ForEach-Object {
    Get-WmiObject Win32_Product -Filter "Name like '%Office%'" -ComputerName $_
    }

    You can find more from this thread
    https://social.technet.microsoft.com/Forums/ie/en-US/0487319d-2db7-4369-b95e-83b74fc17313/powershell-script-to-identify-office-version-on-a-remote-system-using-computer-name?forum=ITCG


    If the reply is helpful, please Upvote and Accept it as an answer

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 97,396 Reputation points MVP
    2021-10-05T07:00:06.767+00:00

    Hi @O'Connor, Tim ,

    you could try this please:

    $Adcomp = "Computer1","Computer2"  
    $Results = ForEach ($Computer in $Adcomp) {  
    $Name = $Computer.Name  
    $bios = Get-WmiObject Win32_Bios -ComputerName $Computer  
    $version = Get-WMIObject -Computername $Computer Win32_Product -Filter "Name like '%office%'"  
    $version  
    }  
    $Results | export-csv C:\Junk\test.csv -NoTypeInformation -Append  
    

    Based on your expected result you should modify the output to your needs.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments