[英]How can I use powershell to get a list of service accounts with interactive logon privileges?
交互式登錄是指登錄類型 2、10 或 11。
我想編寫一個 PowerShell 腳本,它可以給我一個啟用交互式登錄權限的服務帳戶列表。
我嘗試了兩種方法。
我試圖獲取服務帳戶列表,如下所示:
Get-ADServiceAccount -Right -seInteractiveLogonRight
我還嘗試對用戶群體應用過濾器:
Get-ADUser -Filter {name like ‘svc*’} |
Where-Object LogonType -eq 'Interactive'
這兩種方法似乎都不起作用。 第一個,我收到一個語法錯誤,說 -Right 不作為有效參數存在,第二個我沒有得到響應(只是超時)。
幫助/指針表示贊賞。 我對 Powershell 很陌生,如果我遺漏了任何基本內容,我深表歉意。
至於這個……
Get-ADServiceAccount -Right
...該 cmdlet 沒有這樣的參數。 始終,始終檢查幫助文件,對於 cmdlet、function、模塊等,哪些是可能的,哪些是不可能的。
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-ADServiceAccount).Parameters
(Get-Command -Name Get-ADServiceAccount).Parameters.Keys
# Results
<#
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable
AuthType
Credential
Filter
Identity
LDAPFilter
Partition
Properties
ResultPageSize
ResultSetSize
SearchBase
SearchScope
Server
#>
Get-help -Name Get-ADServiceAccount -Examples
Get-help -Name Get-ADServiceAccount -Full
Get-help -Name Get-ADServiceAccount -Online
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-ADUser).Parameters
(Get-Command -Name Get-ADUser).Parameters.Keys
# Results
<#
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable
AuthType
Credential
Filter
Identity
LDAPFilter
Partition
Properties
ResultPageSize
ResultSetSize
SearchBase
SearchScope
Server
#>
Get-help -Name Get-ADUser -Examples
Get-help -Name Get-ADUser -Full
Get-help -Name Get-ADUser -Online
登錄類型在主機上的服務 object 上,而不是通過 AD 用戶/計算機 object 的屬性。
# Get all services
Get-WmiObject -Class Win32_Service -ComputerName $env:ComputerName |
Select-Object -Property DisplayName, StartName, State
# Filter for type
Get-WmiObject -Class Win32_Service -ComputerName $env:ComputerName |
Where-Object { $PSItem.StartName -match 'LocalSystem' } |
Select-Object -Property DisplayName, StartName, State
在策略(GPO 或 LPO)中為用戶/服務帳戶設置權限。
[xml]$report = Get-GPOReport -Name "Default Domain Policy" -ReportType XML
您可以過濾該報告以獲取特定信息。 此外,您可以使用secedit.exe
工具來獲取它們。
secedit 命令
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/secedit
這可以提供權限報告,但您需要翻譯 SID 才能看到簡單英語的名稱。
請參閱此示例:
https://www.powershellbros.com/get-user-rights-assignment-security-policy-settings
盡管該工具早已被貶低,但您仍然可以使用ntrights.exe
工具來獲取該信息。 ntights.exe
工具位於 Windows 資源工具包中。 也就是說,如果您有舊的 MSDN、TechNet 媒體來獲取它,或者知道有人這樣做。 如果不是,你必須做這樣的事情。
Find-Module -Name '*rights*'
# Results
<#
Version Name Repository Description
------- ---- ---------- -----------
1.0.2 cUserRightsAssignment PSGallery The cUserRightsAssignment module contains the cUserRight DSC resource that provides a mechanism to manage user rights:
logon rights and privileges.
#>
或下載並使用此工具...
https://archive.codeplex.com/?p=userrights
UserRights PowerShell 模塊涵蓋以下用例:
...注意:它也是一個遺留工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.