Solved

compare email address

Posted on 2016-09-06
4
52 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 40

Assisted Solution

by:footech
footech earned 125 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 125 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 84

Accepted Solution

by:
oBdA earned 250 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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 article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
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…

737 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