PowerShell->>獲取本地計算機的用戶組和組成員


獲取本地計算機的用戶組和組成員

 

 

function Get-LocalGroups() {
  net localgroup | ?{ $_ -match "^\*.*" } | %{ $_.SubString(1) };
}

function Get-LocalGroupMembers() {
  param ([string]$groupName = $(throw "Need a name") )
  $lines = net localgroup $groupName
  $found = $false
  for ($i = 0; $i -lt ($lines.Length-1); $i++ ) {
    if ( $found ) {
      if ( -not $lines[$i].StartsWith("命令成功完成")) {
        $output = $lines[$i] + "," + $groupName
        Write-Output $output
      }
    } elseif ( $lines[$i] -match "^----" ) {
      $found = $true;
    }
  }
}


function fn(){
  $lines = Get-LocalGroups;
  $found =$false;
  for ($i = 0; $i -lt $lines.Length; $i++ ) {
    if ( -not $lines[$i].StartsWith("命令成功完成")) {
    Get-LocalGroupMembers $lines[$i]
    }
  }
}

fn

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM