Tech

Powershell script to collect Microsoft Office version and key

Can someone please guide me to pull the MS Office Version and Key from provided list of machines.
He’s the command that pulls the last 5 digits of the Key:

 $cred = get-credential
$computers = gc "C:\computer.txt"
foreach($computer in $computers )
{
Invoke-Command -scriptBlock {cscript "C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS" /dstatus}
}

using the above script I am not able to collect the version and key from the remote machines. It just pull the information from the PC I run.

Any help appreciated.