Page 2 of 2

Re: Unable to query remote registry using PowerShell script

Posted: Thu Aug 09, 2018 8:52 pm
by ITEngineer
jvierra wrote:
Thu Aug 09, 2018 7:57 am

Code: Select all

function Get-OfficeVersion{
    param(
        [string]$ComputerName = $env:COMPUTERNAME
    )
    # code to extract Word/Office version
    $hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('localmachine',$ComputerName)
    if($key = $hive.OpenSubKey('Software\Classes\Word.Application\CurVer')){
        $wordApp = $key.GetValue($null)
    }
    switch ($wordApp){
        'Word.Application.17' {'Office 2019'}
        'Word.Application.16' {'Office 2016'}
        'Word.Application.15' {'Office 2013'}
        'Word.Application.14' {'Office 2010'}
        'Word.Application.12' {'Office 2007'}
        'Word.Application.11' {'Office 2003'}
        default {'Not found'}
    }
}
Yes, it works locally Mr. Vierra. :D

Re: Unable to query remote registry using PowerShell script

Posted: Thu Aug 09, 2018 8:58 pm
by ITEngineer
So how is it possible to show the column name of the Computer after modifying the script like below:

Code: Select all

Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "DC=Domain,DC=com" |
	Where-Object {Test-Connection $_.Name -Count 1 -Quiet} |
	Select-Object -Property Name |
	ForEach-Object {
		Get-OfficeVersion $_.Name
	} | Export-Csv -Path C:\OfficeVersion.csv -NoTypeInformation -UseCulture
The first column for Computername is missing.

Re: Unable to query remote registry using PowerShell script

Posted: Thu Aug 09, 2018 11:09 pm
by jvierra

Code: Select all

[pscustomobject]@{
    ComputerName = $_.Name
    OfficeVersion = Get-OfficeVersion $_.Name
}