[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

compare email address

Posted on 2016-09-06
4
Medium Priority
?
63 Views
Last Modified: 2016-09-06
Can you help me with this if statement. It should check to see if the ad users email address is equal to the email address imported from the csv.

Import-Csv "C:\Scripts\accounts\AmigosList.csv" | ForEach-Object {
$SID = $_.STD_ID_LOCAL
$User1 = Get-Aduser -Filter "SamAccountName -eq $SID" -Property SamAccountName
       
            if($User1.EmailAddress -eq $_.Email1){
                write-host "Email is already correct"
                }
            else{
                write-host "fix the email"
               }
}
0
Comment
Question by:Roccat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 41

Assisted Solution

by:footech
footech earned 500 total points
ID: 41786905
Your If statement should work as is if you add "emailAddress" to the -Property parameter of your Get-ADUser command.
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 41786914
If statement should work, probably need to correct the filter syntax for Get-Aduser and add missing email property..
$User1 = Get-Aduser -Filter {SamAccountName -eq $SID} -pr *

Open in new window

or
$User1 = Get-Aduser -Filter 'SamAccountName -eq $SID' -pr *

Open in new window

0
 
LVL 85

Accepted Solution

by:
oBdA earned 1000 total points
ID: 41786920
Can't test it at the moment, but the script below should work.
* Since you have the samAccountName anyway, there's no need for a filter, -Identity is just fine.
* You don't need to specify samAccountName as property, since it's a default property.
* In your own interest, don't use "$SID" for this - it usually means the user's Security Identifier.
* "EmailAddress" is not part of the default set, so you need to specify it in Get-ADUser.
* You won't know for which user the email address is correct or not ...
Import-Csv "C:\Scripts\accounts\AmigosList.csv" | ForEach-Object {
	"Processing $($_.STD_ID_LOCAL) ... "  | Write-Host -ForegroundColor White -NoNewline
	If ($ADUser = Get-Aduser -Identity $_.STD_ID_LOCAL -Property EmailAddress -ErrorAction SilentlyContinue) {
		If ($ADUser.EmailAddress -eq $_.Email1) {
			"email is already correct." | Write-Host -ForegroundColor Green
		} Else {
			"email needs to be fixed." | Write-Host -ForegroundColor Yellow
		}
	} Else {
		"user not found." | Write-Host -ForegroundColor Red
	}
}

Open in new window

0
 

Author Closing Comment

by:Roccat
ID: 41787046
Thanks! This was very helpful.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question