Need help with a new local admin user

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”

I would say please include the error message, but the parameter should be -AccountExpires and not -AccountExpirationDate

darn, Im new to this haha
trying to post without messing up the window :smiley:

Parse is error prone, just use $nDate = (Get-Date).AddDays(1)

oh wow! That did work! Thanks!
I don’t konw about the timelimit yet (obviously) but it looks thats all I needed.
I love learning this stuff. Thank you so much for helping!