初學者問題。我們僅按 AD 組授予對服務器的訪問權限。我們需要報告誰對 Windows 服務器串列具有管理員訪問權限。我的審計員??喜歡我的服務器管理員腳本,但她也想知道組成員的名字和姓氏。如果有更好的方法,我不需要使用 ADGroupMember 腳本。
如果有人能指出我正確的方向,那就太好了。重要的是我明白了,所以我下次可以自己做 :)
提前致謝
$computers = Get-content "c:\scripts\servers.txt"
ForEach ($Line In $computers)
{
#write-host $Line
Invoke-command -ComputerName $line -ScriptBlock { net localgroup administrators} | Get-ADGroupMember -Identity "$_????what goes here????" |%{get-aduser $_.SamAccountName | select userPrincipalName } | out-file "c:\scripts\'$line'LocalAdmin.txt"
}
這個腳本很好用,但沒有首先列出組成員,姓氏
$computers = Get-content "c:\scripts\servers.txt"
ForEach ($Line In $computers)
{
#write-host $Line
Invoke-command -ComputerName $line -ScriptBlock { net localgroup administrators} | out-file "c:\scripts\'$line'LocalAdmin.txt"
}
uj5u.com熱心網友回復:
如果您確實需要有關本地 Administrators組中用戶的資訊,則可以使用 PSv5.1 Microsoft.PowerShell.LocalAccounts模塊中的 cmdlet 。
但是,請注意,本地帳戶只有一個.FullName屬性,而不是分開的名字和姓氏。此外,此屬性可能會或可能不會填寫:
Invoke-Command -ComputerName (Get-Content c:\scripts\servers.txt) -ScriptBlock {
Get-LocalGroupMember -Group Administrators |
Where-Object ObjectClass -eq User |
Select-Object Sid |
Get-LocalUser
} |
Sort-Object PSComputerName |
Select-Object PSComputerName, Name, FullName
如果域用戶在組的成員中,并且您確實需要單獨的名字和姓氏資訊,則通過管道連接到Get-ADUser而不是到Get-LocalUser- 您可以通過.PrincipalSource屬性區分用戶的來源(定義它們的位置),該屬性可在Get-LocalGroupMember來自 Window的輸出物件上使用10 / Windows Server 2016。
uj5u.com熱心網友回復:
mklement0 的有用答案的替代方法,有點老派,使用[adsi]:
$servers = Get-Content c:\scripts\servers.txt
Invoke-Command -ComputerName $servers -ScriptBlock {
$adsi = [adsi]"WinNT://$env:COMPUTERNAME,computer"
$adsi.PSBase.Children.Find('Administrators').PSBase.Invoke('members') |
ForEach-Object {
$Name = $_.GetType().InvokeMember('Name','GetProperty',$null,$_,$null)
$class = $_.GetType().InvokeMember('Class','GetProperty',$null,$_,$null)
$adspath = $_.GetType().InvokeMember('ADSPath','GetProperty',$null,$_,$null)
$sid = [System.Security.Principal.SecurityIdentifier]::new(
$_.GetType().InvokeMember('objectsid','GetProperty',$null,$_,$null),0
).Value
[pscustomobject]@{
Name = $Name
Class = $Class
Path = $adspath -replace '^WinNT://'
SecurityIdentifier = $sid
}
} | Sort-Object Class -Descending
} | Where-Object Class -EQ User
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/379968.html
標籤:电源外壳
