共用方式為


Get-LocalUser

取得本機用戶帳戶。

語法

Default (預設值)

Get-LocalUser
    [[-Name] <String[]>]
    [<CommonParameters>]

SecurityIdentifier

Get-LocalUser
    [[-SID] <SecurityIdentifier[]>]
    [<CommonParameters>]

Description

Cmdlet Get-LocalUser 會取得本機用戶帳戶。 此 Cmdlet 會取得預設的內建用戶帳戶、您建立的本機用戶帳戶,以及您連線到Microsoft帳戶的本機帳戶。

備註

Microsoft.PowerShell.LocalAccounts 模組無法在 64 位系統上的 32 位 PowerShell 中使用。

範例

範例 1:使用其名稱取得帳戶

此範例會取得名為 AdminContoso02 的用戶帳戶。

Get-LocalUser -Name "AdminContoso02"
Name             Enabled Description
----             ------- -----------
AdminContoso02   True    Description of this account.

範例 2:取得連線至Microsoft帳戶的帳戶

此範例會取得連線至Microsoft帳戶的用戶帳戶。 此範例會針對位於 Outlook.com 的帳戶用戶名稱使用佔位元元值。

Get-LocalUser -Name "MicrosoftAccount\username@Outlook.com"
Name                                    Enabled  Description
----                                    -------  -----------
MicrosoftAccount\username@outlook.com  True     Description of this account.

範例 3:取得具有指定 SID 的帳戶

這個範例會取得具有指定 SID 的本機用戶帳戶。

Get-LocalUser -SID S-1-5-21-9526073513-1762370368-3942940353-500
Name          Enabled Description
----          ------- -----------
Administrator True    Built-in account for administering the computer/domain

參數

-Name

指定這個 Cmdlet 取得的使用者帳戶名稱陣列。 您可以使用通配符。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:True
不要顯示:False

參數集

Default
Position:0
必要:False
來自管線的值:True
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-SID

指定此 Cmdlet 取得之用戶帳戶的安全性識別子數位。

參數屬性

類型:

SecurityIdentifier[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

SecurityIdentifier
Position:0
必要:False
來自管線的值:True
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

CommonParameters

此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters

輸入

String

您可以使用管線將字串傳送到此 cmdlet。

SecurityIdentifier

您可以使用管線將 SID 傳送至此 Cmdlet。

輸出

System.Management.Automation.SecurityAccountsManager.LocalUser

此 Cmdlet 會傳回本機用戶帳戶。

備註

Windows PowerShell 包含下列 Get-LocalUser的別名:

  • glu

LocalUserLocalGroupLocalPrincipal 物件的 PrincipalSource 屬性描述對象的來源。 可能的來源如下所示:

  • 本地
  • Active Directory
  • Microsoft Entra 群組
  • Microsoft帳戶

只有 Windows 10、Windows Server 2016 和更新版本的 Windows 操作系統才支援 PrincipalSource。 對於較早的版本,屬性是空白的。