none
Export Email and Proxy Address from Multiple Domains RRS feed

  • Question

  • Hello Friends, 

    I need small help i have a 3 domains like NA, AP and EU and we have users in that now i need to export the email address and proxy from all the users . I tried with below but its not giving the desired output. any help ?

    Domain1:Na.domain.com

    Domain2:EU.domain.com

    Domain3:AP.domain.com

    ---------------------

    Set-ADServerSettings -ViewEntireForest $true
    $domains = (Get-ADForest).domains
    $Members = foreach ($domain in $domains)
    Get-Content C:\Scripts\Get-SamAccountName\users.txt | -Server $Domain ForEach {
    Get-ADUser -Filter "mail -eq '$_'" -Properties * | Select-Object Name, SamaccountName, Mail, @{ L = "ProxyAddresses"; E =
    {($_.ProxyAddresses | Where-Object {$_ -like "*abc.mail.onmicrosoft.com*" }) -join ';'} } } | export-csv c:\Scripts\Get-UserProxyAddress.csv

    Thanks

    Tuesday, September 24, 2019 3:52 AM

All replies

  • I recommend that you start by reading the full help for all CmdLets you are trying to use. What you are doing is guessing with no understanding of what you are guessing.

    You also need to post code correctly using the code posting tool provided. 

    Post the complete error message and read it carefully before posting.


    \_(ツ)_/

    Tuesday, September 24, 2019 4:33 AM
  • Hey Jrv , 

    I need to export the email and proxy address from the multiple domain i know what i am trying to use is not correct so that why i posted here . If you can help will be great . I am trying get what i am looking for but only for one domain. 

    Set-ADServerSettings -ViewEntireForest $true
    Get-Content C:\Scripts\users.txt | ForEach {
    
        Get-ADUser -Filter "mail -eq '$_'" -Properties * | Select-Object Name, SamaccountName, Mail, @{ L = "ProxyAddresses"; E = {($_.ProxyAddresses | Where-Object {$_ -like "*abc.mail.onmicrosoft.com*" }) -join ';'} } } | export-csv c:\Scripts\data.csv
    

    Tuesday, September 24, 2019 4:47 AM
  • What is the error message?

    Read this to understand how to ask a question  in a technical forum:  How to ask questions in a technical forum


    \_(ツ)_/

    Tuesday, September 24, 2019 5:01 AM
  • There is no Error message only the data is not retriving from other domain. I know how to ask a question and if you can not help then please don;t reply. Let others help. thanks  
    Tuesday, September 24, 2019 6:28 AM
  • Ok then this line is hot finding anything:

    Get-ADUser -Filter "mail -eq '$_'"

    The following will help you to see wy this causes no output:

    Get-Content C:\Scripts\users.txt | 
    	ForEach-Object{
        	    Get-ADUser -Filter "mail -eq '$_'" | 
    			Select-Object Name, SamaccountName, Mail, 
    				@{ 
    					n = 'ProxyAddresses'; 
    					e = {
    						($_.ProxyAddresses | Where-Object {$_ -like '*abc.mail.onmicrosoft.com*' }) -join ';'
    					}
    				} 
    	} | 
    	export-csv c:\Scripts\data.csv


    \_(ツ)_/



    • Edited by jrv Tuesday, September 24, 2019 6:46 AM
    Tuesday, September 24, 2019 6:45 AM
  • Now try this:

    Get-Content C:\Scripts\users.txt | 
        ForEach-Object{Get-ADUser -Filter "mail -eq '$_'"} |
        Select-Object Name, SamaccountName, Mail


    \_(ツ)_/

    Tuesday, September 24, 2019 6:48 AM
  • If you get output from the previous then this should work:

    $properties = @(
    	'Name', 
    	'SamaccountName', 
    	'Mail', 
    	@{ 
    		n = 'ProxyAddresses'; 
    		e = {
    			($_.ProxyAddresses | Where-Object {$_ -like '*abc.mail.onmicrosoft.com*' }) -join ';'
    		}
    	} 
    )
    
    Get-Content C:\Scripts\users.txt | 
    	ForEach-Object{Get-ADUser -Filter "mail -eq '$_'"} |
    	Select-Object $properties |
    	export-csv c:\Scripts\data.csv


    \_(ツ)_/

    Tuesday, September 24, 2019 6:51 AM