Unable to query remote registry using PowerShell script

Ask your 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.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

Re: Unable to query remote registry using PowerShell script

Post 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
/* IT Engineer */
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

Re: Unable to query remote registry using PowerShell script

Post 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.
/* IT Engineer */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Unable to query remote registry using PowerShell script

Post by jvierra »

Code: Select all

[pscustomobject]@{
    ComputerName = $_.Name
    OfficeVersion = Get-OfficeVersion $_.Name
}
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked