Powershell设置新本地用户强制更改密码
Powershell setting new local users forced password change
各位下午好,
我有一个简短的问题。我正在制作一个脚本来根据 csv 文件创建本地用户帐户。使用 New-LocalUser
命令,我一切正常。我很好奇的是有一个参数字符串我可以添加或任何有它所以用户 Has 在第一次登录时更改密码?
我已经浏览过了 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1 我只是想知道是否遗漏了什么。
你没有。大多数时候,当发布 cmdlet 时,它们并不包含特定技术的所有功能(例如,Get-Service 与 Win32_Service)。在这种情况下,New-LocalUser、Get-LocalUser、Set-LocalUser 就在这条船上。
但是,为了实现您所追求的,WinNT 提供者很早就公开了此功能:
$u = New-LocalUser -Name test -Password ('123456789' | ConvertTo-SecureString -AsPlainText -Force)
$WinNt = [adsi]"WinNT://localhost/$($u.Name)"
$WinNt.PasswordExpired = 1
$WinNt.SetInfo()
各位下午好,
我有一个简短的问题。我正在制作一个脚本来根据 csv 文件创建本地用户帐户。使用 New-LocalUser
命令,我一切正常。我很好奇的是有一个参数字符串我可以添加或任何有它所以用户 Has 在第一次登录时更改密码?
我已经浏览过了 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1 我只是想知道是否遗漏了什么。
你没有。大多数时候,当发布 cmdlet 时,它们并不包含特定技术的所有功能(例如,Get-Service 与 Win32_Service)。在这种情况下,New-LocalUser、Get-LocalUser、Set-LocalUser 就在这条船上。
但是,为了实现您所追求的,WinNT 提供者很早就公开了此功能:
$u = New-LocalUser -Name test -Password ('123456789' | ConvertTo-SecureString -AsPlainText -Force)
$WinNt = [adsi]"WinNT://localhost/$($u.Name)"
$WinNt.PasswordExpired = 1
$WinNt.SetInfo()