Set-LocalUser
修改本地用户帐户。
语法
Name (默认值)
Set-LocalUser
[-Name] <String>
[-AccountExpires <DateTime>]
[-AccountNeverExpires]
[-Description <String>]
[-FullName <String>]
[-Password <SecureString>]
[-PasswordNeverExpires <Boolean>]
[-UserMayChangePassword <Boolean>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
InputObject
Set-LocalUser
[-InputObject] <LocalUser>
[-AccountExpires <DateTime>]
[-AccountNeverExpires]
[-Description <String>]
[-FullName <String>]
[-Password <SecureString>]
[-PasswordNeverExpires <Boolean>]
[-UserMayChangePassword <Boolean>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
SecurityIdentifier
Set-LocalUser
[-SID] <SecurityIdentifier>
[-AccountExpires <DateTime>]
[-AccountNeverExpires]
[-Description <String>]
[-FullName <String>]
[-Password <SecureString>]
[-PasswordNeverExpires <Boolean>]
[-UserMayChangePassword <Boolean>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Set-LocalUser
cmdlet 修改本地用户帐户。 此 cmdlet 可以重置本地用户帐户的密码。
注释
Microsoft.PowerShell.LocalAccounts 模块在 64 位系统上的 32 位 PowerShell 中不可用。
示例
示例 1:更改用户帐户的说明
Set-LocalUser -Name "Admin07" -Description "Description of this account."
此命令更改名为 Admin07 的用户帐户的说明。
示例 2:更改帐户的密码
$Password = Read-Host -AsSecureString
$UserAccount = Get-LocalUser -Name "User02"
$UserAccount | Set-LocalUser -Password $Password
第一个命令使用 Read-Host cmdlet 提示输入密码。 该命令将密码存储为$Password变量中的安全字符串。
第二个命令使用 Get-LocalUser
获取名为 User02 的用户帐户。 该命令将帐户存储在$UserAccount变量中。
第三个命令设置存储在 $UserAccount
中的用户帐户的新密码。
参数
-AccountExpires
指定用户帐户过期的时间。 若要获取 DateTime 对象,请使用 Get-Date
cmdlet。
如果不希望帐户过期,请指定 AccountNeverExpires 参数。
参数属性
类型: | DateTime |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-AccountNeverExpires
指示帐户不会过期。
参数属性
类型: | SwitchParameter |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | cf |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-Description
指定用户帐户的注释。 最大长度为 48 个字符。
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-FullName
指定用户帐户的全名。 全名不同于用户帐户的用户名。
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-InputObject
指定此 cmdlet 更改的用户帐户。 若要获取用户帐户,请使用 Get-LocalUser
cmdlet。
参数属性
类型: | Microsoft.PowerShell.Commands.LocalUser |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
InputObject
Position: | 0 |
必需: | True |
来自管道的值: | True |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-Name
指定此 cmdlet 更改的用户帐户的名称。
参数属性
类型: | String |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
Name
Position: | 0 |
必需: | True |
来自管道的值: | True |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-Password
指定用户帐户的密码。 如果用户帐户连接到Microsoft帐户,请不要设置密码。
可以使用 Read-Host -AsSecureString
、Get-Credential
或 ConvertTo-SecureString
为密码创建 SecureString 对象。
如果省略 密码 和 NoPassword 参数,Set-LocalUser
会提示输入用户的密码。
参数属性
类型: | SecureString |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-PasswordNeverExpires
指示密码是否过期。
参数属性
类型: | Boolean |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-SID
指定此 cmdlet 更改的用户帐户的安全 ID (SID)。
参数属性
类型: | SecurityIdentifier |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
SecurityIdentifier
Position: | 0 |
必需: | True |
来自管道的值: | True |
来自管道的值(按属性名称): | True |
来自剩余参数的值: | False |
-UserMayChangePassword
指示用户可以更改用户帐户的密码。
参数属性
类型: | Boolean |
默认值: | None |
支持通配符: | False |
不显示: | False |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。
参数属性
类型: | SwitchParameter |
默认值: | False |
支持通配符: | False |
不显示: | False |
别名: | 无线 |
参数集
(All)
Position: | Named |
必需: | False |
来自管道的值: | False |
来自管道的值(按属性名称): | False |
来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
System.Management.Automation.SecurityAccountsManager.LocalUser
可以通过管道将本地用户传递给此 cmdlet。
String
可以通过管道将字符串传递给此 cmdlet。
SecurityIdentifier
可以通过管道将 SID 传递给此 cmdlet。
输出
None
此 cmdlet 不返回任何输出。
备注
Windows PowerShell 为 Set-LocalUser
提供以下别名:
slu
PrincipalSource 属性是 LocalUser、LocalGroup和 LocalPrincipal 对象上的一个属性,用于描述对象的来源。 可能的源如下所示:
- 本地
- Active Directory
- Microsoft Entra 组
- Microsoft 帐户
PrincipalSource 仅受 Windows 10、Windows Server 2016 和更高版本的 Windows 操作系统支持。 对于早期版本,该属性为空。