Powershell - Get Unified Group with Mailaddress of the owners - powershell

I want to send a message to all people who are owners of a public MS Group. So my Code is:
Get-UnifiedGroup -ResultSize unlimited| Where-Object {($_.AccessType -eq "Public")} | Select-Object ManagedBy | Export-csv C:\Path
I can get the names, but how can I get the email address of the owners. I want to have it in one list.

Related

Using filter to find email addresses matching a domain

I'm trying to find email addresses in O365 Exchange that matches a particular domain using PowerShell.
If I use:
Get-Recipient -ResultSize unlimited -filter '(PrimarySMTPAddress -like "*smith*")' | fl primarysmtpaddress
I get all the addresses that have the string
If I use:
Get-Recipient -ResultSize unlimited -filter '(PrimarySMTPAddress -like "*#domain*")' | fl primarysmtpaddress
I get no results.
It looks like nothing is matched after the #.
I want to use -filter rather than a where statement because it is so much faster.
I was able to reproduce your issue. It seems to be related to the the specific attribute you filtered on, "PrimarySMTPAddress".
I was able to get the filter statement to return results by changing it to leverage "EmailAddresses", another attribute the email address is stored in:
Get-Recipient -ResultSize unlimited -filter '(EmailAddresses -like "*#domain*")' | fl primarysmtpaddress
Something else I saw of note: the "filterable properties" documentation mentions avoiding using "PrimarySMTPAddress" for another reason that I didn't know of:
Don't use the PrimarySmtpAddress property; use the EmailAddresses property instead. Any filter that uses the PrimarySmtpAddress property will also search values in the EmailAddresses property. For example, if a mailbox has the primary email address dario#contoso.com, and the additional proxy addresses dario2#contoso.com and dario3#contoso.com, all of the following filters will return that mailbox in the result: "PrimarySmtpAddress -eq 'dario#contoso.com'", "PrimarySmtpAddress -eq 'dario2#contoso.com'", or "PrimarySmtpAddress -eq 'dario3#contoso.com'".
Source
https://learn.microsoft.com/en-us/powershell/exchange/filter-properties?view=exchange-ps

How to use AD groups to assign O365 mailbox sizes

Is there a way to do the above? I've managed to follow the below link successfully but we're looking to set different limits based on the user's role.
The aforementioned link
Where is says :
Additional filters can be applied to the Get-Mailbox cmdlet or to the Get-User cmdlet to control the users for whom the change is applied. The following is an example in which three cmdlets are used to filter the command to the sales department of an organization:
Get-User | where {$_.Department -eq "Sales"} | Get-Mailbox | Set-Mailbox -ProhibitSendQuota < Value > -ProhibitSendReceiveQuota < Value > -IssueWarningQuota < Value >
Kinda got me confused as to where it's pulling the "Sales" group from?
Probably being a muppet here but any help appreciated.
You could do this, using the Active Directory PowerShell module:
Get-ADUser -Filter * -Properties Department | Where-Object { $_.Department -eq "Sales" } | [...]
But that's just pulling everybody and looking at the Department field from Active Directory. That's the example the article gives, but it doesn't answer your question about assigning quotas based on groups.
I suspect what you'll want based on your problem is this:
Get-ADGroupMember -Identity $GroupName | Get-ADUser | Get-MailBox | Set-ProhibitSendQuota [...]
I don't know if you need Get-ADUser there or if the output of Get-ADGroupMember can be piped directly to Get-MailBox. I no longer administer Exchange, so I don't have access to those cmdlets anymore. $GroupName can be the group's name, distinguished name, or even the SID, IIRC.

Using Powershell to get Office 365 SMTP: email addresses

Found the exact script I need:
https://unlockpowershell.wordpress.com/2010/01/27/powershell-get-mailbox-display-smtp-addresses/
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, #{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}
When I run this using Powershell5 against Office 365, "Email Addresses" is returned blank.
Any ideas?
This may have worked on Exchange 2007/2010, where the blog post says it was tested, but O365 mailboxes are a little different.
The EmailAddresses property of a mailbox object in O365 is an array list containing strings and they have no PrefixString property here. The issue is at this point
Where-Object {$_.PrefixString -ceq “smtp”}
Since PrefixString doesn't exist, you get blank results.
Instead, since the EmailAddresses array is just a bunch of strings, you can filter on those directly.
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,ServerName,PrimarySmtpAddress, #{Name=“EmailAddresses”;Expression={$_.EmailAddresses | Where-Object {$_ -clike “smtp*”}}}

Powershell Script to Pull Various Data Fields in Active Directory

This is what I currently have to pull a specific facility list of all departments. What I now need to discover is the various Job Titles they have for this facility, the tricky part is that the Titles are not listed within the attributes for the user accounts within active directory. The titles are only listed under Organization tab -> Job Title. Simply adding "title" into the code does not work since that field is left blank where the script is trying to pull it from, I just need to redirect it to pull from the Job Title field under the Organization tab.
Get-ADUSER -LDAPFilter "(extensionattribute7=)"-properties department | select-object name,department -unique | Sort-object department |
Select Department -unique | Export-Csv -NoType MyCSVfile.csv
If you add Title to the -Properties parameter, it will be returned by Get-ADUser. But if your Select-Object statements don't include it, it will be discarded.
You may want to do this in multiple statements instead of a single pipeline.
$users = Get-ADUSER -LDAPFilter "(extensionattribute7=)"-properties department,title
$depts = $users | Select-Object Department -Unique
$titles = $users | Select-Object Title -Unique

Get SMTP address from a list of Names (Exchange 2013 powershell)

I'm trying to get SMTP address's for users who have OWAEnabled. I have what I think are two pieces that do what I want, but I can't figure out how to put them together. Ultimately it will output the SMTP address's to a CSV.
Get-CASMailbox -Filter{OWAEnabled -eq $true} | Select-Object Name
This gets me a list of user "Names" who have OWA enabled.
Get-Mailbox -ResultSize Unlimited | Select-Object PrimarySmtpAddress
This gets me Primary SMTP Address's
How do I put the two together? Sorry, i'm relatively new to PS.
Thanks for any help! :)
PrimarySMTPAddress is already a property of a CASMailbox object, so you just need to select it:
Get-CASMailbox -Filter{OWAEnabled -eq $true} | Select-Object Name,PrimarySMTPAddress
Most objects will have properties that aren't part of the default display properties, so they don't display by default.
Get-CasMailbox <identity> | format-list *
and you'll see all the available properties.