共用方式為


DSC 使用者資源

適用於:Windows PowerShell 4.0、Windows PowerShell 5.x

Windows PowerShell 預期狀態設定 (DSC) 的 User 資源,會提供在目標節點管理本機使用者帳戶的機制。

注意

此 DSC 資源的本檔涵蓋 7.2 版之前 PowerShell 隨附的版本。 PSDscResources模組包含 Microsoft 正式支援的全新和更新 DSC 資源。 PSDscResources 模組可從 PowerShell 資源庫中取得。

如需詳細資訊和更新的檔,請參閱 PSDscResources 參考檔

語法

User [string] #ResourceName
{
    UserName = [string]
    [ Description = [string] ]
    [ Disabled = [bool] ]
    [ FullName = [string] ]
    [ Password = [PSCredential] ]
    [ PasswordChangeNotAllowed = [bool] ]
    [ PasswordChangeRequired = [bool] ]
    [ PasswordNeverExpires = [bool] ]
    [ DependsOn = [string[]] ]
    [ Ensure = [string] { Absent | Present }  ]
    [ PsDscRunAsCredential = [PSCredential] ]
}

屬性

屬性 描述
UserName 指出您要確保其特定狀態的帳戶名稱。
描述 表示您要使用的使用者帳戶描述。
已停用 表示帳戶是否啟用。 將此屬性設定為 $true 以確保此帳戶已停用,而將它設定為 $false 可確定它已啟用。
FullName 代表有您要使用的完整使用者帳戶名稱的字串。
密碼 表示您想要用於這個帳戶的密碼。
PasswordChangeNotAllowed 表示使用者是否可以變更密碼。 將此屬性設定為 $true 以確保使用者無法變更密碼,而將它設定為 $false 可允許使用者變更密碼。 預設值是 $false
PasswordChangeRequired 表示使用者是否必須在下次登入時變更密碼。 如果使用者必須變更密碼,請將此屬性設定為 $true。 預設值是 $true
PasswordNeverExpires 表示密碼是否會到期。 為確保這個帳戶的密碼永遠不會到期,請將這個屬性設定為 $true。 如果密碼會到期,則將其設定為 $false。 預設值是 $false

通用屬性

屬性 描述
DependsOn 表示必須先執行另一個資源的設定,再設定這個資源。 例如,如果第一個想要執行的資源設定指令碼區塊識別碼是 ResourceName,而其類型是 ResourceType,則使用這個屬性的語法就是 DependsOn = "[ResourceType]ResourceName"
Ensure 表示帳戶是否存在。 將此屬性設定為 Present 以確保帳戶存在,並將它設定為 Absent 以確保帳戶不存在。 預設值為 Present
PsDscRunAsCredential 設定用於執行整個資源的認證。

注意

已在 WMF 5.0 中新增 PsDscRunAsCredential 通用屬性,以允許在其他認證的內容中執行任何 DSC 資源。 如需詳細資訊,請參閱搭配 DSC 資源使用認證

範例

User UserExample
{
    Ensure = "Present"  # To ensure the user account does not exist, set Ensure to "Absent"
    UserName = "SomeName"
    Password = $passwordCred # This needs to be a credential object
    DependsOn = "[Group]GroupExample" # Configures GroupExample first
}