Email Notification Script or Command Help ifnay New room mailbox Created

Ramki 816 Reputation points
2021-12-24T07:07:56.48+00:00

Dear All

Am looking for a command, or script to notiffy me, if any one created a new room maibox in exchange environment . My environmemnt is hrybbied exchnage 2016.

check if nay room mailbox created in last 24 hours , and then send an email to me , if any room mailbox created in last 24 hours.

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,193 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,358 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
1,896 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,211 Reputation points
    2021-12-27T07:42:41.45+00:00

    @Ramki

    You could use script below to check it:

    $mailbox = Get-Mailbox -ResultSize unlimited -RecipientTypeDetails RoomMailbox  | where{$_.WhenMailboxCreated -gt (get-date).AddHours(-24)} | select Name  
      
    If ($Mailbox -eq $null){  
        $Subject = "No Room Mailbox created within 24 hours"  
    }Else{  
        $body =""  
        $Subject = "Mailboxes Created within 24 hours"   
        foreach ($item in $mailbox) {  
            $body = $body + $item.name + " "  
        }  
    }  
      
    $From = "TestUser@domain.com"  
    $password = "1234"  
    $To = "TestUser2@domain.com"                 
    $smtpServer = "mail.domain.com"  
    $smptport= '587'  
      
      
    $SMTPMessage = New-Object System.Net.Mail.MailMessage($From, $To,$Subject,$Body)  
    $SMTPClient = New-Object System.Net.Mail.SmtpClient($smtpServer, $SmtpPort)   
    $SMTPClient.EnableSsl = $true  
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($From, $password);   
    $SMTPClient.Send($SMTPMessage)  
    

    You need to edit the 13~16 lines before using it.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



1 additional answer

Sort by: Most helpful
  1. Andy David - MVP 142.2K Reputation points MVP
    2021-12-24T13:20:41.247+00:00

    Create a scheduled task that connects to Exchange and runs once a day:

    $NewMailboxes = Get-Mailbox -ResultSize unlimited  -RecipientTypeDetails RoomMailbox  |?{$_.WhenMailboxCreated -gt (get-date).AddHours(-24)}
    
    $Report = (
    
    $NewMailboxes.userprincipalname|
    Sort-Object UserPrincipalname |
    ft -AutoSize |
    Out-String
    
    
    
    )
    $count = ($NewMailboxes).Count
    if ($($NewMailboxes | measure).Count -gt 0) {send-mailmessage -to you@contoso.com -smtpserver **yourMailServer** -subject " $count Room Mailboxe(s) Created in the last hour" -From 
    user@contoso.com -Body $Report}