我试图在使用 Out-GridView 显示对象之前添加内容。我正在执行下面的方法,但是收到错误消息。我对 Powershell 对象不够熟悉,无法理解我在这里做错了什么。
任何指导都值得感激!
$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
$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
此方法不是合并对象然后显示,而是在遍历范围时获取“空闲 IP”的数量。不确定这是否正是您想要的,但它将提供您在 cmdlet 中指定的输出,Out-Gridview
并且它应该将相同的信息“传递”到您从代码段中留下的任何内容。请确保选择您想要“传递”的范围。