Reputation: 99
I'm working on a small script to make adding users to our AD easier. It's just a one line New-ADUser powershell script that asks for inputs. It looks like this:
New-ADUser -Name (Read-Host "User Name") -AccountExpirationDate 0 -CannotChangePassword 1 -ChangePasswordAtLogon 0 -PasswordNeverExpires 1 -Company (Read-Host "Company") -Department (Read-Host "Department") -Title (Read-Host "Title") -Manager (Read-Host "Manager's User Name") -GivenName (Read-Host "Full Name") -MobilePhone (Read-Host "Cell Phone Number") -State (Read-Host "State") -AccountPassword (Read-Host -AsSecureString "Password") -ProfilePath (Read-Host "Roaming Profile Path") -Path (Read-Host "AD Path to User")
It asks for everything like it should but after inputting everything it returns: "New-ADUser : Not a valid Win32 FileTime. At line:1 char:11." I checked that location in the command (it's the space after "New-ADUser") and I don't know why it would return that.
Is this an efficient way of doing what I want? How can I fix my command to not return the error? Is it what I'm inputting into the spots?
Upvotes: 0
Views: 7112
Reputation: 1
For Windows Server 2016 the problem above exists, and the solution above does not work (completely).
I have found a workaround.
Yes, the Technet page above has an error; unfortunately, that also results in the PowerShell scripting system having a problem parsing the script
So - Error #1 - If you use the command New-ADUser
as specified with 0
as the parameter, you get error New-ADUser : Not a valid win32 FileTime.
When you change 0
to $null
, you get Error #2 - The term '(the next parameter in your command)' is not recognized as the name of a cmdlet, function
I found the following solution to completely solve the problem:
Change (as above) -AccountExpirationDate $null
Move this parameter to the LAST Parameter! Otherwise, you then end up with the error where the next item is incorrectly parsed. You'll note that in the IDE where the parameter shows up in the wrong color.
Upvotes: 0