表格未显示新行的输出

时间:2014-05-29 19:07:57

标签: powershell format

我确信有一个简单的解决方案,但我被卡住了。成员列中的输出就像这样

  

{domain \ Domain Admins,domain \ joerod ...

如何显示

  

$构件

每行的价值?

Function Get-AdminGroups{

foreach($i in (Get-Content C:\Users\joerod\Desktop\remove_users.txt)){

#test if machine is on the network
if (-not (Test-Connection -computername $i -count 1 -Quiet -ErrorAction SilentlyContinue)) {
        Write-Warning "$i is Unavalible"
        "`r"
        }
 else {
(invoke-command {
$members = net localgroup administrators | 
 ? {$_ -AND $_ -notmatch "command completed successfully"} | 
 select -skip 4
New-Object PSObject -Property @{
 Computername = $env:COMPUTERNAME
 Users=$members
 }
} -computer $i -HideComputerName | 
Select * -ExcludeProperty RunspaceID )
  }
}
 }
Get-AdminGroups |ft

1 个答案:

答案 0 :(得分:1)

遍历$ members并为每个成员创建一个对象。这将创建一个空数组,循环遍历文本文件中的计算机,并在该循环中提取本地管理员的列表,并为每个管理器创建一个自定义对象,就像您正在做的那样,并将其添加到该数组中

$Results = @()
foreach($i in (GC C:\Users\joerod\Desktop\remove_users.txt)){
    #test if machine is on the network
    if (!(Test-Connection -computername $i -count 1 -Quiet -ErrorAction SilentlyContinue)) {
        Write-Warning "$i is Unavalible`r"
        Continue
    }
    invoke-command {
        $members = net localgroup administrators |?{$_ -AND $_ -notmatch "command completed successfully"} | select -skip 4
        ForEach($member in $members){
            $Results += New-Object PSObject -Property @{
                Computername = $env:COMPUTERNAME
                Users=$member
            }
        }
    } -computer $i -HideComputerName # | Select * -ExcludeProperty RunspaceID
}
$Results | FT