Changing Password Expires field and updating user:
$localuser = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" -Filter "LocalAccount='$True'" | where {$_.Name -eq $user}
$localuser.PasswordExpires = $false
$localuser.Put()
Here are a list of the properties that can be read or changed.
Properties:
AccountType Property uint32 AccountType {get;set;}Caption Property string Caption {get;set;}Description Property string Description {get;set;}Disabled Property bool Disabled {get;set;}Domain Property string Domain {get;set;}FullName Property string FullName {get;set;}InstallDate Property string InstallDate {get;set;}LocalAccount Property bool LocalAccount {get;set;}Lockout Property bool Lockout {get;set;}Name Property string Name {get;set;}PasswordChangeable Property bool PasswordChangeable {get;set;}PasswordExpires Property bool PasswordExpires {get;set;}PasswordRequired Property bool PasswordRequired {get;set;}SID Property string SID {get;set;}SIDType Property byte SIDType {get;set;}Status Property string Status {get;set;}
Example:
Happy Hunting with automatingtry{$user = "User"$userpass = "Pass"$localuser = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" -Filter "LocalAccount='$True'" | where {$_.Name -eq $user}if($localuser){Write-Host "$user was already created"}else{& net user "$user" "$userpass" /ADD$localuser = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" -Filter "LocalAccount='$True'" | where {$_.Name -eq $user}if($localuser){& net localgroup administrators $user /add$localuser.PasswordExpires = $false$localuser.Put()}else{throw "User Creation failed"}}}catch{throw $error[0]exit 1}finally{$userpass = ""}
No comments:
Post a Comment