如何列出仅启用本地管理员
尝试仅列出在Windows Workstation上启用的本地管理员帐户。
到目前为止,请使用此代码,但是我正在遇到问题,超出了这一点,试图比较活动用户是否是管理员。
$enabledUsers = (Get-LocalUser | Select * | sort Name, FullName, Enabled) | where-object enabled -eq $true
$enabledUsers | Select Name, Fullname
Trying to list only local administrator accounts that are enabled on windows workstations.
Have this code so far but I am running into issues beyond this point trying to compare if the active user is an administrator.
$enabledUsers = (Get-LocalUser | Select * | sort Name, FullName, Enabled) | where-object enabled -eq $true
$enabledUsers | Select Name, Fullname
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
get-localgroupmember
获取管理员
组的所有成员,但是此cmdlet不会告诉我们是否启用了返回的用户,我们可以通过 每个用户到get-localuser
:在此示例中使用了
-ea 0
(- eroration-eroraction sillycontinue
)组的可能不是类用户,在这种情况下,cmdlet会丢下错误(我们想避免)。如果您需要
localuser
对象而不是localprincipal
对象,则可以使用此方法:You can use
Get-LocalGroupMember
to get all members of theAdministrators
group, however this cmdlet doesn't tell us if the returned users are Enabled, we can pass the SID of each user toGet-LocalUser
and filter for those Enabled ones:-EA 0
(-ErrorAction SilentlyContinue
) is used in this example because the members of the group may not be of the class User, in which case, the cmdlet would throw an error (which we want to avoid).If you need
LocalUser
objects instead ofLocalPrincipal
objects, you can use this instead:如果您还需要过滤AD管理员
If you need to filter out AD admins as well