Powershell – Using Powershell to change user properties in XP

powershelluser-managementwindows-xp

Is it possible to use PowerShell to change local user settings on Windows XP (without Active Directory), specifically the settings on the user properties tab – such as "Password never expires" and groups that the user is a member of?

Samples would be great, but a pointer to the relevant documentation would be great too – I'm not even sure what to look for.

Best Answer

The simplest way is to direct ADSI queries to the local WinNT provider - that will return local objects on the system you are interested in. These can be local or remote systems but this will attach to the local account and security objects rather than the AD.

$user = [ADSI]"WinNT://joe-pc/joe"

With that you can then query and modify properties of the $user object.

To set the "Password Doesn't expire" Flag you need to set the relevant flag in the UserFlags attribute. You can find a useful table of these at Motobit here.

To forcibly set Joe's account password from the above example to never expire:

$Never_Expire=0x10000
$user.UserFlags.value=$user.UserFlags.value -bor $Never_Expire

Modifying group memberships is a bit more involved but Microsoft's PowerShell Guy has a step by step walk though for adding Domain User accounts to a Local Group on a system which I think is exactly what you need.