Using the below script:
Import-Csv "\\server\input.csv" | Foreach {Get-ADUser -Filter "EmployeeID -eq '$($_.EID)'"
-Properties EmployeeID, SamAccountName, Enabled, proxyAddresses } |
Select-Object EmployeeID, SamAccountName, Enabled, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like '*@mycompany.org' ) -join ";"}}
I would also like to find any other proxy addresses a user has that are not from this '@mydomain.org' but are primary that start with 'SMTP:'
Example:
@{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like '*@mycompany.org' ) **AND ALSO LIKE THIS** -join ";"}}
CodePudding user response:
Getting a joined list of addresses that are not from a specific domain, but begin with "SMTP" indicating it's primary, then the calculated expression should look like the below.
@{
Label = "ProxyAddresses";
Expression = {
(
$_.ProxyAddresses -notlike '*@mydomain.org' -and
$_.ProxyAddresses -like 'SMTP*'
) -join ";"
}
}
Filter out the domain you want to exlcude with the -notlike
operator and only return primary addresses using -like
to match from the beginning.
CodePudding user response:
It seems you want all addressed that have either @mydomain.org
OR start with all caps SMTP:
(==> primary address) and do NOT have @mydomain.org
.
In that case you can use below:
Import-Csv -Path "\\server\input.csv" | ForEach-Object {
# Get-ADUser by default already returns objects with these properties:
# DistinguishedName, DNSHostName, Enabled, Name, ObjectClass, ObjectGUID, SamAccountName, SID, UserPrincipalName
# so you only have to ask for the extra's you need with parameter Properties
Get-ADUser -Filter "EmployeeID -eq '$($_.EID)'" -Properties EmployeeID, proxyAddresses } |
Select-Object EmployeeID, SamAccountName, Enabled,
@{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like '*@mycompany.org' -or
($_.ProxyAddresses -notlike '*@mycompany.org' -and
$_.ProxyAddresses -clike 'SMTP:*')) -join ";"}}