Hi
I am trying to write a script to import AD users from a csv file. I have managed to get it working apart from one bit. As we have a number of offices I don't want to have to specify the full address for each user when the csv file is populated. I want to set each address part as a variable in the script so that the script does a check against 1 field (office) in the input file and sets the address based on that. I have tried the code below but it returns an error of:
New-ADUser : A positional parameter cannot be found that accepts argument 'False'.
This is my script:
Import-Csv -Path UserAccounts.csv | ForEach-Object {
$off = $_.office
$OFF1STREET = "Some Street"
$OFF1CITY = "SomeCity"
$OFF1COUNT = "SomeCounty"
$OFF1POST = "SomePostcode"
$OFF2STREET = "Some Street"
$OFF2CITY = "SomeCity"
$OFF2COUNT = "SomeCounty"
$OFF2POST = "SomePostcode"
$OFF3STREET = "Some Street"
$OFF3CITY = "SomeCity"
$OFF3COUNT = "SomeCounty"
$OFF3POST = "SomePostcode"
New-ADUser
-GivenName $_.FirstName
-SurName $_.LastName
-DisplayName ($_.LastName + ", " + $_.FirstName)
-name ($_.LastName + ", " + $_.FirstName)
-SamAccountName $_.SamAccountName
-Description $_.Desc
-office $_.office
-officephone ($phone + $_.tele)
-HomePage $_.web
-UserPrincipalName ($_.SamAccountName + "@domain.com") -Enabled:$true
-streetAddress
if($off -eq "off") {$OFF1STREET}
elseif($off -eq "off2") {$OFF2STREET}
else {$OFF3STREET}
-country "GB"
-AccountPassword (ConvertTo-SecureString -AsPlainText 'password' -Force) -ChangePasswordAtLogon:$true
}
Would be very grateful if someone is able to point out what I'm doing wrong.
Thanks.
↧