2015-06-21 46 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)}「你對此有什麼想法? –