How to pull Primary SMPT from secondary SMTP

Welcome Forums General PowerShell Q&A How to pull Primary SMPT from secondary SMTP

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
3 months, 1 week ago.

  • Author
    Posts
  • #113212

    Participant
    Points: 0
    Rank: Member

    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

     

  • #113260

    Participant
    Points: 30
    Rank: Member

    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
    	}
    }
    
    • #113308

      Participant
      Points: 0
      Rank: Member

      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

    • #113309

      Participant
      Points: 0
      Rank: Member

      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

  • #113312

    Participant
    Points: 1,091
    Helping Hand
    Rank: Community Hero

    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.

The topic ‘How to pull Primary SMPT from secondary SMTP’ is closed to new replies.