3

This script work but the output to the .csv in the release id field is everything associated with the registry key. All I want in the field is the release id number (1909, 1809, 1709). How to I edit this script just to write only that information to the output file? Below is a sample of the output I now get. Below that is the script I am using.

The output I get now.

@{ReleaseId=1909; PSPath=Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion; PSParentPath=Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT; PSChildName=CurrentVersion; PS

The script I am using is below.

$Computers = get-content "C:\Temp\computers.txt"

$( foreach ($Computer in $Computers) { $result = Invoke-Command -ComputerName $Computer -scriptBlock { Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId }

    [PSCustomObject]@{
        ComputerName = $Computer
        ReleaseID = $Result
    }

} ) | Export-Csv "C:\Temp\GetReleaseID.csv" -NoType

Invoke-Item "C:\Temp\GetReleaseID.csv"

webby68
  • 250

1 Answers1

3

Use Select-Object to select object properties.

Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion' -Name ReleaseId | Select-Object -ExpandProperty ReleaseId 

For more information on this cmdlet run Get-Help Select-Object -Full

jfrmilner
  • 2,197