An IF Statement

by Nov 6, 2018

I'm attempting to create a script, to create AD Accounts. One portion using an IF statement is giving me troubles. I've tried so many variations using ForeEach and ForeEach-Object. But I get nothing, not even errors.

My current script is….

$UList=(Import-Csv "\SERVERSHAREFolderFile.csv")

ForEach-Object {

If ($_Department -eq "APD"){

Write-Host -b White -f Red "This is if Statement for Dewy.Seemore"

Add-QADGroupMember -Identity `$A-DWN -Member Dewy.Seemore


Else {

Write-Host "$_.SamAccountName is not in Group"


# $UList


In the above script, There are no errors returned. From what I've tried, If I remove the remark from the near last line (# $UList) I do get a list of the headings from my csv file, and the values for the headings. I have two entries in the csv, one is True and the other is False for matching $_Department. If I place the $UList up in the "IF" section, I get nothing. So this tells me that my expression never returns true that $_Department equals APD.

My CSV file, has two entries. One row have APD as the value for Department, and the other row has a different value, not APD.  Can anyone tell me what is wrong with my IF statement?

In my 5th and 6th lines, I would typically not have a Write-Host, and the actual name of an account would be replaced with $_.SamAccountName

I've tried ForeEach ( $UL in UList ) {, and tried $UL_.SamAccountName, as well as $UL_.Department….

thank you, any help would be much appreciated.