Hi
I have a list of user’s secondary SMTP and I am trying to find the Primary one based on that list.
This is my script which doesn’t work as expected.
get-aduser -Properties * | Where-Object $._proxyaddresses -Like (Get-Content C:\Temp\SMTP\list.txt) | ForEach-Object {
? {$_ -match ‘^smtp’} {
[pscustomobject]@{
name = $_.name
SMTPproxyaddresses = $addr
}
}
}
Any pointers would be highly appreciated.
Cheers, M
There is a lot going on there - but I checked and I have something from earlier this year I wrote for work with our office 365 migration - and here is a modified version below.
for efficiency you only want to get the users which are in your file - i used csv - but you can change the import-csv to get-content (and then change the get-aduser line)
foreach ($Item in Import-Csv c:\temp\users.csv)
{
$user = Get-ADUser $($Item.user) -Properties proxyaddresses
$primaySMTP = ( $user | Select-Object -ExpandProperty | Where-Object{ $_ -clike "SMTP:*" }).replace("SMTP:", "")
[pscustomobject]@{
"Name" = "$($user.name)"
"SMTPProxyAddressses" = ($user.proxyaddresses) -join ";"
"PrimarySMTP" = $primaySMTP
}
}
Hi
The csv will contain only the users smtp address so proxyaddresses but smtp from which i want to pull the SMTP address.
Your script iterates on user which is not on the csv.
M
Hi
The csv will contain only the users smtp address so proxyaddresses but smtp from which i want to pull the SMTP address.
Your script iterates on user which is not on the csv.
M
Your script seems to be broken or incomplete.
From what I understood, you are trying to get all the users whose proxy addresses are in your list.
$SMTP = Get-Content -Path C:\Temp\SMTP\list.txt
Get-ADUser -Filter * -Properties * | Where-Object {$._proxyaddresses -in $SMTP} | ForEach-Object -Process {
#Do what you want
}
Note: Get-AdUser has identity as a default mandatory parameter, if you don’t have a specific identity but need all , you have to use -filter with *(wildcard) as value.
And you have to put your script between the pre tags for formatting when posting in the forum.