2015-06-21 33 views
0

我们需要每月为我们的服务器提取一份报告,报告所有服务器的管理员访问权限。这将帮助我们移除不再访问的人员需要。它花费大量的时间来手动提取,并且我在博客上看到PowerShell被用来自动执行这种类型的管理工作。获取正在为我的服务器访问服务器的用户

其他详情: 服务器 - 赢得2008 R2 Powershell 1.0 任何人都可以帮助我如何提取此报告?

回答

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

+0

感谢您的解决方案..我已经尝试过SOME其他服务器与它的Powershell 3.0,它的工作:)我可以保存结果到CSV? –

+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

+0

最好的方法可能是通过'Invoke-Command'远程执行上述操作(在目标计算机上启用了PSRemoting)。 –

+0

嗨,杰森。感谢您的答复。我们在我们的服务器中使用powershell 1.0,当我尝试第一个语句“distinguishedName -----------------”是我的结果,当我尝试完成下面的脚本时错误消息“异常调用”调用“1”参数:“找不到成员。 (例外从HRESULT:0x80020003(DISP_E_MEMBERNOTFOUND))“ 在行:1字符:16 + @($ group.Invoke(<<<<”Members“))| foreach {$ _。GetType()。InvokeMember(”名称“,”GetProperty',$ null,$ _,$ null)}“你对此有什么想法? –