Unable to query remote registry using PowerShell script

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
ITEngineer
Posts: 68
Joined: Wed Oct 12, 2011 10:52 am

Re: Unable to query remote registry using PowerShell script

Post by ITEngineer » Thu Aug 09, 2018 8:52 pm

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
/* IT Engineer */

User avatar
ITEngineer
Posts: 68
Joined: Wed Oct 12, 2011 10:52 am

Re: Unable to query remote registry using PowerShell script

Post by ITEngineer » Thu Aug 09, 2018 8:58 pm

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.
/* IT Engineer */

User avatar
jvierra
Posts: 12550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Unable to query remote registry using PowerShell script

Post by jvierra » Thu Aug 09, 2018 11:09 pm

Code: Select all

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

Post Reply