Hello all,
I am new to coding and have taught myself a lot of what I need and use.
I need to create a new local admin user that will expire after a one time login, or a day if that isn’t possible.
I have compiled some codes and got the following, but I recieve several errors on the expiry code.
Is there a something I put in here wrong, or is there a better expiry code?
Username and Password
$username = “USERNAME”
$password = ConvertTo-SecureString “PASSWORD” -AsPlainText -Force
$ExpireDate = $Line.‘Contract Expiration’
$nDate = [DateTime]::Parse($ExpireDate)
if ($ExpireDate -eq “”) {$AccountExpiryDate = [DateTime]::Now.AddYears(1)}
else {$AccountExpiryDate = $nDate.AddDays(1)}
Creating the user
New-LocalUser -Name “$username” -Password $password -FullName “$username” -AccountExpirationDate $AccountExpiryDate -Description “One Time Login”
Setting admin attribute
Add-LocalGroupMember -Group “Administrators” -Member “USERNAME”