I'm a bit new to this. I understand how the if statement works but can't understand how to best do this with all the parameters I have to check for.
I'm already using an IF Else statement to check an ISACTIVE column because I need to have certain user accounts enabled/disabled. I tried passing values to the -Enabled AD parameter but ended up having to do this because it wouldn't take it.
I'm confused on where to add the extra if statements to do this check. Here is my code so far. I've seen examples from others using $hash=@{} but don't know how I can implement it into my current script. SIGH!
$csv = Import-csv 'C:\PSScripts\(ProdTest).csv' -Delimiter '|' Foreach ($user in $csv) { $name = $givenName + " " + $surName $sAMAccountName = $user.USER_NAME $officePhone = $user.PHONENUMBER $emailAddress = $user.EMAIL $givenName = $user.FNAME $surName = $user.LNAME $company = $user.COMPANY $department = $user.DEPARTMENT $streetAddress = $user.ADDRESS $city = $user.CITY $state = $user.STATE $country = $user.COUNTRY $postalCode = $user.ZIPCODE $accountPassword = $user.PASSWORD $enabled = $user.ISACTIVE $OU = "ou=Application,dc=contoso,dc=lab" $upn = $sAMAccountName + "@contoso.lab" if ($user.ISACTIVE -eq 'Y') { new-aduser -Name $name ` -SamAccountName $sAMAccountName ` -OfficePhone $officePhone ` -EmailAddress $emailAddress ` -Path $OU ` -DisplayName $name ` -UserPrincipalName $upn ` -GivenName $givenName ` -Surname $surName ` -Department $department ` -City $city ` -State $state ` -PostalCode $postalCode ` -AccountPassword (ConvertTo-SecureString $accountPassword -AsPlainText -Force) ` -Enabled $true ` -ChangePasswordAtLogon $false } else { new-aduser -Name $name ` -SamAccountName $sAMAccountName ` -officePhone $officePhone ` -EmailAddress $emailAddress ` -Path $OU ` -DisplayName $name ` -UserPrincipalName $upn ` -GivenName $givenName ` -Surname $surName ` -Department $department ` -City $city ` -State $state ` -PostalCode $postalCode ` -AccountPassword (ConvertTo-SecureString $accountPassword -AsPlainText -Force) ` -Enabled $false ` -ChangePasswordAtLogon $false }}