I have tried with many different combinations (including brackets). We are using Exchange 2010 Hybrid environment with O365.
Mailboxes that are migrated to the O365, become "Mail Contact" objects and are no longer being included in our Dynamic Distribution Groups.
Basically I want all on-premise user mailboxes, and "Remote User Mailbox" (not all Mail Contacts) to be included in the filter selection. Where organization is "AB*", my attempt is below:
Set-DynamicDistributionGroup -Identity "Test Filter Group" -RecipientFilter {RecipientType -eq 'UserMailbox' -or RecipientType -eq 'MailUser' -or RecipientType -eq 'MailContact' -and Company -eq 'AB*' -and isMailboxEnabled -eq '$true' -and ObjectCategory -eq 'person' -or ObjectCategory -eq 'users' -and ObjectClass -eq 'user' -and RecipientTypeDetails -ne '16'}
Can someone please help!?
Related
I'm trying to create a DDG with powershell that returns all users that have mobile phone.
I've checked which propireties are filtrable and I've created the group with:
New-DynamicDistributionGroup -Name "Groupname" -RecipientFilter "(RecipientType -eq 'UserMailbox') -and (Phone -ne '$null')"
And the group gets created successfully, but when I try to see the user in group with the command below I get this error:
$FTE = Get-DynamicDistributionGroup "GroupName"
Get-Recipient -RecipientPreviewFilter $FTE.RecipientFilter -OrganizationalUnit $FTE.RecipientContainer
The recipient preview filter string "((Phone -ne '') -and (-not(Name -like 'SystemMailbox{*')) -and (-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue
-eq 'MailboxPlan')) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) -and
(-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')) -and (-not(RecipientTypeDetailsValue -eq
'AuxAuditLogMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')))" is neither a valid OPath filter nor a valid LDAP filter. Use the
-RecipientPreviewFilter parameter with either a valid OPath filter string or a valid LDAP filter string.
all the other filter string are created automatically buy exchange I guess, what could be the issue?
Thank you for your help.
I am trying to get only active AD Users in AD which satisfies below conditions:
samaccountname is not null
mail is not null
mail ends with a domain, in this case what is contained in #oldDomain variable
As a demo, I have also filter by only a samaccountname. Below is not working:
$Users = Get-ADUser -Filter {(samaccountname -ne "null") -and (samaccountname -eq "TestUserPruebasSI") -and (Enabled -eq "true") -and (mail -ne "null") -and "mail -like '*$oldDomain'"}
The culprit is the last criteria "mail -like '*$oldDomain'". If I remove it then query Get-ADUser works.
So how can I solve this?
Using below works:
$Users = Get-ADUser -Filter "samaccountname -ne 'null' -and samaccountname -eq 'TestUserPruebasSI' -and Enabled -eq 'true' -and mail -ne 'null' -and mail -like '*$oldDomain'"
Here is code I'm using to add users to two groups based on the company they are part of. Now how can I make it so if the user is already part of the groups it skips that user and moves on to the next one.
Get-Aduser -filter 'company -eq "1480"' | %{Add-ADPrincipalGroupMembership -Identity $_.SamAccountName -MemberOf "HS", "HS Students" -WarningAction SilentlyContinue}
Get-ADUser -Filter "-not (memberOf -eq 'CN=MyPermanentGroup,CN=Users,DC=Fabrikam,DC=com') -and -not (memberOf -eq 'CN=MyOtherGroup,CN=Users,DC=Fabrikam,DC=com') -and company -eq '1480'"
I'm trying to generate a mailbox report for our hosted Exchange platform and automate things a bit. Basically each tenant is in an OU. So I'm trying to first pull a list of OU's, then count the mailboxes in each OU. Here's what I have so far:
$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })
foreach ($ou in $ous) {
(Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count
}
It works... sort of. The result will be a ton of numbers on each line, a mailbox count for each OU. Problem is, then I have OU's in the $ous variable, and I'm outputting the count to the screen. What I need is output two columns, the OU, alongside the count in another column, so I can pipe it into Export-CSV cmdlet so I can have client name (OU), and the count in a CSV file to them email.
I'm just not sure how to get that combination of data all at once.
Easiest way to organise information is to put it into an object, if you need to alter the data later on it's already in an object that you can manipulate.
$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })
foreach ($ou in $ous)
{
# This is how many mailboxes this OU has
$mailboxCount = (Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count
# This is a fancy object to store our information
$mailboxObject = New-Object psobject -Property ([Ordered]`
#{
"OU" = $ou
"MailboxCount" = $mailboxCount
})
# You can export your CSV here or do other stuff
# $mailboxObject | Export-CSV C:\MyPath -NoTypeInformation
}
Small note: If you're not using PowerShell v3 take out the [Ordered] attribute :)
If I'm understanding you correctly, the answer is very simple. This will output csv content. If you'd prefer, you can drop the quotes and replace the comma with a `t, then you can copy/paste from the PowerShell console into Excel.
$ous = (Get-ADOrganizationalUnit -SearchBase "OU=Microsoft Exchange Hosted Organizations,DC=yomamma,DC=com" -Filter { (ObjectClass -eq 'organizationalunit') -and (Name -notlike 'Hosted Organization Security Groups') -and (Name -Notlike 'Microsoft Exchange Hosted Organizations') })
foreach ($ou in $ous) {
'"' + $ou.Name + '",' + (Get-Mailbox -Organization $ou.Name -Filter {( Name -notlike 'Administrator' -and Name -notlike 'DiscoverySearch*' )} -ResultSize unlimited).count
}
I am having the hardest time figuring this out. I am trying to import a list of office numbers from a csv that corresponds to the office numbers in specific users profiles for that office. For example, i am trying to find all the contractors and customer service employees only for all offices listed. so in column A it should be listing the offices and column B should list the users for that office in a single row joined by a ; but some reason i get no output no errors. What am i doing wrong?
import-csv "C:\scripts\offices.csv" |
foreach {get-aduser -properties * -filter {office -eq "$($_.office)" -and title -eq "Independent contractor" -or office -eq "$($_.office)" -and title -eq "Sr customer service Rep"} |
select #{n='Name';e={$_.Name -join '; '}}} |
export-csv "c:\temp\users in each office.csv" -notypeinformation
Untested, but I think you need to wrap the conditions with () to group them appropriately. Something like this:
-filter {(office -eq "$($_.office)" -and title -eq "Independent contractor") -or (office -eq "$($_.office)" -and title -eq "Sr customer service Rep")}
Or you could change it to this as well:
-filter {office -eq "$($.office)" -and (title -eq "Independent contractor" -or title -eq "Sr customer service Rep")}
Didn't test, but an obvious error is the missing underscore in your filter:
-filter {office -eq "$($.office)"
should be:
-filter {office -eq "$($_.office)"