获取对我的服务器具有服务器访问权限的用户

时间:2015-06-21 02:11:53

标签: powershell

我们需要每个月为我们的服务器提取一份报告,该报告应报告所有人都拥有服务器管理员权限。这将帮助我们删除不再需要访问权限的人员。它花了很多时间手动提取,我在博客上读到PowerShell用于自动执行此类管理工作。

其他细节: 服务器 - 赢取2008 R2 Powershell 1.0 任何人都可以帮助我如何提取这份报告吗?

2 个答案:

答案 0 :(得分:1)

这是一种枚举服务器管理员列表的快捷方法。

$group = [ADSI]"WinNT://./Administrators"

@($group.Invoke("Members")) | foreach {
  $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
}

然后,您可以使用电子邮件cmdlet发送它,或者您想将其发送回给您。

请参阅:http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/27/the-admin-s-first-steps-local-group-membership.aspx

答案 1 :(得分:0)

不需要ADSI和PSRemoting。例如:

$cComputerNames = @("computer1", "computer2")
$cRows = @()

foreach ($sComputerName in $cComputerNames) {
    $cAdminAccounts = Get-WmiObject -ComputerName $sComputerName `
        -Class "Win32_GroupUser" `
        | Where-Object { 
            ($_.GroupComponent -split '"')[3] -eq "Administrators" 
          }
    foreach ($cAdminAccount in $cAdminAccounts) {
        $oRow = New-Object -TypeName PSObject -Property @{
            "ComputerName"  = $sComputerName
            "AccountDomain" = ($cAdminAccount.PartComponent -split '"')[1]
            "AccountName"   = ($cAdminAccount.PartComponent -split '"')[3]
        }
        $cRows += $oRow
    }
}

$cRows | Export-Csv -Path "admin-accounts.csv" -NoTypeInformation

您可以使用associators of ...查询来获取有关帐户的更多详细信息。请参阅this blog post