locked
Exporting PC Name and Office version with powershell RRS feed

  • Question

  • Hi, i've found some powershell scripts to export Office versions on remote PCs and combined them together. Here it is:

    foreach ($computer in (Get-Content "C:\computers.txt")){
      write-verbose "Working on $computer..." -Verbose
      Invoke-Command -ComputerName "$Computer" -ScriptBlock {
        Get-WmiObject win32_product -ComputerName "$Computer" | where{$_.Name -like "Microsoft Office Standard*"} | select Name,Version
      } | export-csv C:\results.csv -Append -NoTypeInformation
    }

    The question is "Is there any way to export computer name in csv as well?"

    I've tried different ways but I'm quite noob in powershell so none of them worked. 

    Thank you!


    • Edited by escpoar Thursday, January 9, 2020 6:25 AM
    Thursday, January 9, 2020 6:24 AM

Answers

  • Finally found

    foreach ($computer in (Get-Content "C:\computers.txt")){
      write-verbose "Working on $computer..." -Verbose
      Invoke-Command -ComputerName "$Computer" -ScriptBlock {
        Get-WmiObject win32_product -ComputerName "$Computer" | where{$_.Name -like "Microsoft Office Standard*"} | select Name,Version,@{name=»Computer«; expression={$Computer}}
      } | export-csv C:\results.csv -Append -NoTypeInformation
    }

    • Marked as answer by escpoar Thursday, January 9, 2020 11:53 AM
    Thursday, January 9, 2020 11:53 AM