I have a script that creates a user and assigns a password and a user to a group, but I need to set two checkboxes - “User cannot change password” and “Password never expires”, but I can’t figure out how to do it for the service life.
My script so far:
# Create User and add to IGNITEWEBUSERS Group $user = $domain # If more then 15 chars trim to just 15 chars $user = $user.substring(0, 15) $user = $user + "_web" # Generate Random Complex Password # Generate a password with 2 non-alphanumeric character. $Length = 10 $Assembly = Add-Type -AssemblyName System.Web $RandomComplexPassword = [System.Web.Security.Membership]::GeneratePassword($Length,2) $password = $RandomComplexPassword $group = 'IGNITEWEBUSERS' $objOu = [ADSI]"WinNT://$computer" $objUser = $objOU.Create("User", $user) $objUser.setpassword($password) $objUser.SetInfo() $objUser.description = $domain + " IIS User" $objUser.SetInfo() $OBjOU = [ADSI]"WinNT://$computer/$group,group" $OBjOU.Add("WinNT://$computer/$user")
This works and does what it should do, but does anyone know how I can set these 2 checkboxes? Various themes offer something similar to Set-ADUser -CannotChangePassword:$true , but I do not use Active Directory, and this does not work.
Your advice is welcome.
Floor
source share