[英]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.