3

I am attempting to add on to an object before displaying it with an Out-GridView. I am doing the method below however get an error message. I'm not strong enough in Powershell objects to understand what I'm doing wrong here.

Any guidance is appreciated!

$scopes = Get-DhcpServerv4Scope -ComputerName $SERVERNAME
$scopeObject = @{}
foreach ($scope in $scopes) {
    $stats = Get-DhcpServerv4ScopeStatistics -ComputerName 'nfiv-dhcp-02' -ScopeId $scope.ScopeId 
    $scopeObject.Add($scope.ScopeId,$scope.Name,$stats.Free)
}

$scopeObject | Out-GridView -Passthru -Title "DHCP Server Scopes on $SERVERNAME"

1 Answer 1

3
$SERVERNAME = "your DHCP server's name here"
$scopes = Get-DhcpServerv4Scope -ComputerName $SERVERNAME
$scopes | Select-Object -Property ScopeId,SubnetMask,Name,State,StartRange,EndRange,LeaseDuration,`
  @{ E={(Get-DhcpServerv4ScopeStatistics -ScopeId $_.ScopeId.IpAddressToString -ComputerName $SERVERNAME).Free}; L='Free' }`
  | Out-GridView -PassThru -Title "DHCP Server Scopes on $SERVERNAME" | Some-Cmdlet

Instead of merging objects then displaying, this method grabs the number of "Free IPs" while iterating through the scopes. Not sure if this is exactly what you want, but it will give the output you specify in your Out-Gridview cmdlet and it should "PassThru" that same information to whatever you've left off from your snippet. Make sure you select the scopes you'd like to "PassThru."

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .