It’s one of several pseudo-attributes that may get added during hydration of serialized data.
Either do the select-object (again) on the results of Invoke-Command, or update FormatData/TypeData for Invoke-Command.
--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ntpowershell...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ntpowershell/CADy1Ce7jBbszUEWNj68H8JMNC%3DTx2J4VtwkLv5Cgt9iKK1146A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/68e32e853c6342fda5b49dfd181fff47%40smithcons.com.
I wrote much of the original code in that DHCP documentation script 😊
I take feedback – what do you find confusing about it?
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Kurt Buff, GSEC/GCIH/PCIP
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce6CWA7gwQA%3D9P_pcSG7%2BKC%3D2Nosfgp9Rd-F%3DV1m-BMBXg%40mail.gmail.com.
The problem with your script is twofold: [1] you don’t pass a necessary param to one of your invoke-commands, and [2] you are checking all scopes for all servers scanned. I expect that it would work with the first server and fail with all subsequent servers, once [1] is fixed.
The below works (limited testing: my lab and two prod environments).
BTW, it would be much faster to:
[1] create a PSSession for each DHCPServer so that PSRemoting is only instantiated once for each DHCPServer, OR
[2] have a more complex scriptblock that returns a PSCustomObject containing all the results from each DHCPServer (again, PSRemoting is only instantiated once for each DHCPServer).
$ServerOptions = @()
$Scopes = @()
$ScopeIDs = @()
$ScopeOptions = @()
$DHCPServers = Get-DhcpServerInDC | Sort-Object -Unique DNSName | Select-Object -Expand DNSName
ForEach ($DHCPServer in $DHCPServers)
{
$localServerOptions = @( Invoke-Command -ComputerName "$DHCPServer" -Scriptblock { Get-DhcpServerv4OptionValue | Select-Object OptionId,Name,Value,PSComputerName } )
$localServerScopes = @( Invoke-Command -ComputerName "$DHCPServer" -Scriptblock { Get-DhcpServerv4Scope | Select-Object ScopeId,Name,State,Description,PSComputerName } )
$localScopeIds = @( foreach( $scope in $localServerScopes ) { $scope.ScopeId.ToString() } )
$localScopeOptions = @( foreach( $scopeId in $localScopeIds ) {
Invoke-Command -ArgumentList $scopeId -ComputerName "$DHCPServer" -Scriptblock {
Param( $scopeId )
Get-DhcpServerv4OptionValue -ScopeId "$scopeId" | Select-Object OptionId,Name,Value,PSComputerName
}
} )
$ServerOptions += $localServerOptions
$Scopes += $localServerScopes
$ScopeIds += $localScopeIds
$ScopeOptions += $localScopeOptions
}
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Kurt Buff, GSEC/GCIH/PCIP
Sent: Friday, December 11, 2020 12:40 PM
To: ntpowe...@googlegroups.com
Subject: Re: [ntpowershell] Don't understand why I'm seeing this
No change when looking at properties.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce6CWA7gwQA%3D9P_pcSG7%2BKC%3D2Nosfgp9Rd-F%3DV1m-BMBXg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/348a5ab1715044c1aba131215a6a07a7%40smithcons.com.
I’m not sure what you mean? I think this is functionally equivalent and measurably faster:
$ServerOptions = @()
$Scopes = @()
$ScopeIDs = @()
$ScopeOptions = @()
$DHCPServers = Get-DhcpServerInDC | Sort-Object -Unique DNSName | Select-Object -Expand DNSName
ForEach ($DHCPServer in $DHCPServers)
{
$result = Invoke-Command -ComputerName $DHCPServer {
$options = @( Get-DhcpServerv4OptionValue | Select-Object OptionId, Name, Value, PSComputerName )
$scopes = @( Get-DhcpServerv4Scope | Select-Object ScopeId, Name, State, Description, PSComputerName )
$scopeIds = @( foreach( $scope in $scopes ) { $scope.ScopeId.ToString() } )
$scopeOpts = @( foreach ( $scopeId in $scopeIds ) { Get-DhcpServerv4OptionValue -ScopeId $scopeId | Select-Object OptionId, Name, Value, PSComputerName } )
[PSCustomObject] @{
ServerOptions = $options
ServerScopes = $scopes
ScopeIds = $scopeIds
ScopeOptions = $scopeOpts
}
}
$ServerOptions += $result.ServerOptions
$Scopes += $result.ServerScopes
$ScopeIds += $result.ScopeIds
$ScopeOptions += $result.ScopeOptions
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/1daaf630-2d90-1387-7c05-b2add82771c2%40univie.ac.at.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/348a5ab1715044c1aba131215a6a07a7%40smithcons.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/767f22483a964340853a4b282eecc1ed%40smithcons.com.
Your Select-Object for Get-DhcpServerv4OptionValue doesn’t include ScopeId. Of course it isn’t in the list. 😊
Computers are funny that way. 😊
But after checking – it’s not even available, so it has to be a constructed attribute.

Like this (change line 14 from the v2 script):
$scopeOpts = @( foreach ( $scopeId in $scopeIds ) { Get-DhcpServerv4OptionValue -ScopeId $scopeId | Select-Object @{ N = 'ScopeId'; E = { $scopeid } }, OptionId, Name, Value, PSComputerName } )
In regards to scriptblock parameters – it isn’t obvious and OFTEN BUT NOT ALWAYS you can avoid that by using a special “scope modifier” called “using:”. Because it doesn’t always work, I use ArgumentList instead. It always works. In your specific case, you could’ve said $using:scopeId instead of ArgumentList, but you had to do one or the other.
For more information on this topic (both about using: and ArgumentList) see “help about_remote_variables”.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce7Zr-Gh220FQ7-SWuLOjX_JGYFWOgrFsvQt7fxYDGWZUg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/109fc63031304692b9de1cd9e48312f5%40smithcons.com.