3

How can I do the same think as the following WMIC commands in powershell?

wmic UserAccount where Name='LocalUser' set PasswordExpires=False

wmic useraccount where name='LocalUser' set passwordchangeable=false
1

2 Answers 2

4

With the WMI cmdlets available since version 2.0 of PowerShell, that would be something like:

Get-WmiObject Win32_UserAccount -Filter 'Name = "LocalUser"' |Set-WmiInstance -Arguments @{PasswordExpires=$false}
Get-WmiObject Win32_UserAccount -Filter 'Name = "LocalUser"' |Set-WmiInstance -Arguments @{PasswordChangeable=$false}
1

If you have PowerShell 5.1, you can use:

Set-LocalUser -Name 'LocalUser' -PasswordNeverExpires:$false -UserMayChangePassword:$false

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .