Thursday, 15 August 2013

powershell if statement not executing

powershell if statement not executing

I am trying to write a Powershell script to automate AD user creation. We
are a mixed Linux/Windows environment and use a text (now CSV) file to
keep track of old linux UID #'s and usernames so they don't accidentally
get re-used. I'm trying to get my script to parse the file but I can't
seem to get the comparison to work.
$sam = $GivenName.substring(0,1).ToLower() + $lastname.ToLower()
$usernames=Import-csv "uid.csv"
ForEach($users in $usernames){
if($usernames.username -contains $sam){$uid = $true}
}
I've used several different ways that I've found from around the web to
read the data into an array from the file but the problem seems to be that
no matter what, it never sets $uid = $true and I have no idea why.

No comments:

Post a Comment