Get-OfficeGraphUnifiedGroups.ps1

So I had a need to find all the office 365 unified groups in an office 365 tenant, see if they are active and if they are a team.

So I wrote this.
https://drive.google.com/open?id=1rIq3GbNWWdMSr9fSdgiM7lqeZ3eKGH6J

It uses Office 365 graph and I assumes you have already setup office graph access.  If you have not, check out this link to set things up.
https://blogs.technet.microsoft.com/dawiese/2017/04/15/get-office365-usage-reports-from-the-microsoft-graph-using-windows-powershell/

Let me know what you think!

UPDATE:
YouTube demo can be found here: https://youtu.be/zjN9_WxbXDA

 

Office 365 SMTP Relay Using Windows PowerShell

We are looking to the future, and getting ready to remove OnPrem Exchange.  To do this we need to deal with SMTP Relay.

Microsoft have this doc to help: https://support.office.com/en-gb/article/How-to-set-up-a-multifunction-device-or-application-to-send-email-using-Office-365-69f58e99-c550-4274-ad18-c805d654b4c4

But I wanted to code it ;-)

Quite simple, you need to use an Exchange Online Account:
$Password = "#mailbox password"
$emailFrom = "#mailbox"
$SMTPServer = "smtp.office365.com"
$SMTPPort = 587
$emailTo = "#recipient"
$msgsubject = "testing testing 1-2-3"
$msgBody = "hello world"
$message = New-Object Net.Mail.MailMessage($emailFrom, $emailTo, $msgsubject, $msgBody)
$message.IsBodyHTML = $True

$smtp = New-Object Net.Mail.SmtpClient($SMTPServer,$SMTPPort)
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($emailFrom, $Password);
$smtp.Send($message)

enjoy

Using Windows PowerShell to Find an AD User across multiple domains

So, I have a single forest with multiple domains.  I wanted to use the native ActiveDirectory module for find a SamAccountName.

I came up with this:

$sam = "mysam"
$domains = (Get-ADForest).domains
ForEach($domain in $domains){
  Write-Host $domain
  Get-ADUser -Filter 'SamAccountName -eq $sam ' -Server $domain -Properties *| select DistinguishedName
}

Then I had a brain fart!  Why not use a GC?  Its quicker ;-)

$sam = "mysam"
$forest = (Get-ADForest).Name + ":3268"
Get-ADUser -Filter 'SamAccountName -eq $sam' -Server $forest -Properties * | select DistinguishedName

enjoy!

Office 365 Groups and Primary SMTP Addresses

So here is an interesting one.

We know Office 365 groups are a hybrid Exchange Online / SharePoint Online thing.

When you create an Office 365 Group, it creates an MSOLGroup and a UnifiedGroup object, that you can access using Windows Powershell (Get-MsolGroup / Get-UnifiedGrou).

Any email addresses that are set as Primary on the unified group, replicate up to the MSOLGroup object.

Now, you can remove them from the unified group, but they will NEVER be removed the MSOLGroup object.  Try it ;-)

This means, if you need to do say a Tenant to Tenant migration, and the default msoldomain is a vanity domain, all office 365 groups will have the vanity domain as primary and you cannot remove it!

The only fix, is to delete the group! -or- raise a call with Microsoft and have your engineer engage with the Microsoft Online Domain Services Backend team (Azure AD) to remove them for you.

Enjoy

 

 

 

List Office 365 Administrators

So, I had a need to see who the other Global Admin are my Tenant.  Knocked this up to help.

The following assumes you already have a remote powershell session to Office 365!

$msoladmin = @()
$roles = Get-MsolRole
ForEach($role in $roles){
  $n = $role.Name
  Write-Host $n " " -NoNewLine -f Green
  [array]$tAdmin = Get-MsolRoleMember -RoleObjectId $role.ObjectId | Select *, @{Expression={$n};l="Role"}
  Write-Host $tAdmin.Count
  $msoladmin += $tAdmin
}
$msoladmin | sort Role,DisplayName | select DisplayName, Role

Monitor-MailboxDatabaseCopyStatus.ps1

#Exchange2010 #MsExchange #Powershell

Hello every Happy New Year and all that .. long time to talk.

Wanted to share this.  Basically had a Cisco UCS Blade failure today, where it took 2 nodes of a 3 node Exchange 2010 dag out.

Its been a fun day! NOT!

Anyway, I knocked this script up to monitor the database copy status when we put everything back.

PARAM([String]$Server = (HOSTNAME),
[int]$time            = 30)

Write-Host "Server:.."$Server
Write-Host "Timer:..."$time
$position = $host.ui.rawui.cursorposition
$position.y = $position.y+4
while($True){
  Get-MailboxDatabaseCopyStatus -Server $Server
  $endpos = $host.ui.rawui.cursorposition
  for($i=1;$i-le $time;$i++){write-host "." -nonewline -f Yellow;sleep 1}
  $host.ui.rawui.cursorposition=$endpos;
  Write-Host (" "*$time)
  $host.ui.rawui.cursorposition=$position;
}

Find Exchange Databases using Powershell

A small change in $strFilter=”(objectClass=msExchPrivateMDB)” and you get all the mailbox databases ;-)

$forest    = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Dom  = "LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=" + $Forest.Name.Replace(".",",DC=")
$strFilter="(objectClass=msExchPrivateMDB)"
$Root       = New-Object DirectoryServices.DirectoryEntry $Dom 
$selector   = New-Object DirectoryServices.DirectorySearcher 
$selector.PageSize    = 1000 
$selector.Filter      = $strFilter 
$selector.SearchRoot  = $root 
$selector.SearchScope = "Subtree" 
$Objs = $selector.findall() 
$Objs.count 
$Objs 

Find Exchange Servers using Powershell

#Powershell #MsExchange

I have a suite of discovery scripts that I use every now and then.  I adapted this to look in the AD and get a list of the exchange servers!

$forest    = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Dom = "LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=" + $Forest.Name.Replace(".",",DC=")
$strFilter="(objectClass=msExchExchangeServer)"
$Root       = New-Object DirectoryServices.DirectoryEntry $Dom
$selector   = New-Object DirectoryServices.DirectorySearcher
$selector.PageSize   = 1000
$selector.Filter     = $strFilter
$selector.SearchRoot = $root
$selector.SearchScope = "Subtree"
$Objs = $selector.findall()
$Objs.count
$Objs

#Powershell Export-Clixml and Import-Clixml

I had a need to store some user data.  Using the Exchange 2010 Management Shell I could use Get-User and Get-Mailbox to get what I needed, but when you export it to CSV, some of the fields don’t export very well at all.I was looking at all kinds of funky ways to export the data, but then stumbled upon Export-Clixml.

I was amazed.  I could run say Get-Mailbox bob | Export-Cixml bob.xml

Then I could run $x = Import-Clixml bob.xml anywhere and I would have a variable ($x) with bob’s mailbox information in!

How cool is that!