我想獲取 Windows 服務器上的活動本地用戶串列。當我這樣做時Get-LocalUser,我得到以下輸出
Name Enabled Description
---- ------- -----------
DefaultAccount False A user account managed by the system.
Guest False Built-in account for guest access to the computer/domain
labadmin True Built-in account for administering the computer/domain
Test True
WDAGUtilityAccount False A user account managed and used by the system for Windows Defender Application Guard scen...
我嘗試GetLocalUser -Enabled True并得到以下錯誤
Get-LocalUser : A parameter cannot be found that matches parameter name 'Enabled'.
At line:1 char:79
... ng = New-Object Text.UTF8Encoding $false; Get-LocalUser -Enabled True
~~~~~~~~
CategoryInfo : InvalidArgument: (:) [Get-LocalUser], ParameterBindingException
FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetLocalUserCommandnon-zero return code
過濾掉禁用用戶的正確引數是什么?
uj5u.com熱心網友回復:
Get-Help -Name "Get-LocalUser"(也寫成help get-localuser)會告訴你唯一可用的引數是:
SYNTAX
Get-LocalUser [[-Name] <String[]>] [<CommonParameters>]
Get-LocalUser [[-SID] <SecurityIdentifier[]>] [<CommonParameters>]
并且沒有引數可以過濾啟用的用戶。您需要回傳結果,然后進行過濾。根據您問題的結果,該Enabled列顯示用戶物件可能有一個名為的屬性Enabled,您可以檢查過濾:
$users = Get-LocalUser
$enabledUsers = $users | Where-Object { $_.Enabled }
如果您不知道這一點,或者因為列名與屬性名不完全相同而不起作用,您可以運行$users | Get-Member以查看用戶物件具有哪些屬性,然后查看它們以進行檢查。結果中顯示已啟用:
TypeName: Microsoft.PowerShell.Commands.LocalUser
Name MemberType Definition
---- ---------- ----------
Clone Method Microsoft.PowerShell.Commands.LocalUser Clone()
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AccountExpires Property System.Nullable[datetime] AccountExpires {get;set;}
Description Property string Description {get;set;}
Enabled Property bool Enabled {get;set;}
FullName Property string FullName {get;set;}
LastLogon Property System.Nullable[datetime] LastLogon {get;set;}
Name Property string Name {get;set;}
ObjectClass Property string ObjectClass {get;set;}
PasswordChangeableDate Property System.Nullable[datetime] PasswordChangeableDate {get;set;}
PasswordExpires Property System.Nullable[datetime] PasswordExpires {get;set;}
PasswordLastSet Property System.Nullable[datetime] PasswordLastSet {get;set;}
PasswordRequired Property bool PasswordRequired {get;set;}
PrincipalSource Property System.Nullable[Microsoft.PowerShell.Commands.PrincipalSource] PrincipalSource {ge...
SID Property System.Security.Principal.SecurityIdentifier SID {get;set;}
UserMayChangePassword Property bool UserMayChangePassword {get;set;}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/358619.html
