# Get registry value; forest DCs

**URL:** <https://forums.powershell.org/t/get-registry-value-forest-dcs/15228>\
**Category:** PowerShell Help\
**Created:** [November 13, 2020, 9:39am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228 "2020-11-13T09:39:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 13, 2020, 9:39am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/1 "2020-11-13T09:39:05Z")

</div>

Having trouble getting this to run.

```
$DCs = [DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() |
    Select-Object -ExpandProperty Sites |
        Select-Object -ExpandProperty Servers |
            Select-Object -ExpandProperty Name

foreach( $dc in $DCs ) {(Invoke-Command -ComputerName $dc {(Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Kdc -Name "PerformTicketSignature")}}
```

…as I can’t find out how to resolve the missing ‘)’

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 13, 2020, 10:50am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/2 "2020-11-13T10:50:59Z")

</div>

Why do you think it’s missing? I think you have an extra one that’s not needed. Properly format/indent and it would be easier to see where an extra/missing one is.

```
foreach( $dc in $DCs ){
    Invoke-Command -ComputerName $dc -ScriptBlock {
        (Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Kdc -Name "PerformTicketSignature")
    }
}
```

The parenthesis around your command is also unnecessary.

```
foreach( $dc in $DCs ){
    Invoke-Command -ComputerName $dc -ScriptBlock {
        Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Kdc -Name "PerformTicketSignature"
    }
}
```

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 16, 2020, 6:57am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/3 "2020-11-16T06:57:15Z")

</div>

Thank you Doug, it runs now.

I added some leaner output:

```
foreach( $dc in $DCs ) {
    Invoke-Command -ComputerName $dc {
        Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Kdc -Name "PerformTicketSignature" |
           Sort-Object -Property PSComputerName -Descending | select PSCOMPUTERNAME,PerformTicketSignature |
                Export-Csv -Path C:\Temp\RegistryValue.csv -NoTypeInformation

    }
}
```

…but

1. I get a “RunspaceID” column that’s not particular useful. Any way to trim that?
2. Anyway to sort by Domain? As it is, it’s rather random looking…domains’ DCs mixed around each other (yet the first part of the name is not alphabetical either)
3. How do I capture in a csv, the output sorted on? I thought I would have at least the output (mangled as it was) in the requested csv.

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [November 16, 2020, 7:37am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/4 "2020-11-16T07:37:33Z")

</div>

> [@](#):
>
> 1. I get a “RunspaceID” column that’s not particular useful. Any way to trim that?

RunspaceID and PSComputerName properties are automatic when running Invoke-Command. There is a -HideComputerName switch which will get rid of the PSComputerName but not one just for RunspaceID. The best way to “select” the properties you want is to pipe the output to Select-Object and put the properties you want to see in the -Property parameter. Or you can use the -excludeProperty parameter for properties you want to exclude.

Get-Help [Select-Object](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Select-Object?view=powershell-5.1)

Get-Help [Invoke-Command](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Invoke-Command?view=powershell-5.1)

> [@](#):
>
> 1. Anyway to sort by Domain? As it is, it’s rather random looking…domains’ DCs mixed around each other (yet the first part of the name is not alphabetical either)

Pipe output to Sort-Object and pass the properties you want to sort on to the Property parameter

Get-Help [Sort-Object](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Sort-Object?view=powershell-5.1)

> [@](#):
>
> 1. How do I capture in a csv, the output sorted on? I thought I would have at least the output (mangled as it was) in the requested csv.

Pipe output to Export-CSV

Get-Help [Export-CSV](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-5.1)

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 16, 2020, 8:34am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/5 "2020-11-16T08:34:48Z")

</div>

I believe I’ve done already in the code I posted what you’ve suggested (separately, but you don’t really indicate what order might be tripping up the efficacy of the “sort” I’m looking for, in particular).

Your suggestions (with two separate examples of “Pipe Output to”) are in my code. The help files only account _one_ of those situations (per cmdlet). I’m trying to get both to work together.

And even so, when I try your suggestions by changing up the names of the various Property’s, PS balks that “a positional parameter cannot be found that accepts argument” for all of the property’s I tried (and am I’m only interested in "PCCOmputerName and/or “PerformTicketSignature”

I’ll keep playing with it but thank you for the second set of eyes.

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [November 16, 2020, 8:42am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/6 "2020-11-16T08:42:56Z")

</div>

Your pipes are inside the script block of the Invoke-Command cmdlet. That means they are running on the remote machine, not yours. Try it this way:

```
Invoke-Command -ComputerName $DCs {
    Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Kdc -Name "PerformTicketSignature" 
} | Sort-Object -Property PSComputerName -Descending |  
        Select-Object PSCOMPUTERNAME,PerformTicketSignature |
                Export-Csv -Path C:\Temp\RegistryValue.csv -NoTypeInformation
```

The foreach loop is unnecessary because Invoke-Command will take an array of strings in the ComputerName parameter.

---

<div class="post-metadata">

**Author:** ![jeff-taylor](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeff-taylor/32/1015_2.png) [@jeff-taylor](https://forums.powershell.org/u/jeff-taylor)\
**Post date:** [November 16, 2020, 9:48am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/7 "2020-11-16T09:48:44Z")

</div>

Thanks Mike. Those two suggestions fixed both my sorting problem and formatting. Finished code:

```
$DCs = [DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest() |
    Select-Object -ExpandProperty Sites |
        Select-Object -ExpandProperty Servers |
            Select-Object -ExpandProperty Name

    Invoke-Command -ComputerName $DCs {
        Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Kdc -Name "PerformTicketSignature" } |
           Sort-Object -Property PSComputerName | select PSCOMPUTERNAME,PerformTicketSignature |
                Export-Csv -Path C:\Temp\RegistryValue.csv -NoTypeInformation
```

Your comment about “foreach unnecessary…because Invoke-Command will take an array of strings in the ComputerName parameter.” is because this portion of the Help file, correct?

> Invoke-Command [[-ComputerName] \<String[]\>]

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [November 16, 2020, 11:14am UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/8 "2020-11-16T11:14:28Z")

</div>

Yep. If the documentation puts after the argument type that means it will accept an array of that type. Glad you got it working.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/get-registry-value-forest-dcs/15228/9 "2024-05-16T20:28:19Z")

</div>


