Simple script to see any new emails in Office365

Is there a Powershell or VBS or batch script that can be run which will show you quickly similar to an inbox, for Office365 emails, perhaps specifycing
simply any new emails received in an Inbox with From, Subject and Time.. like a quick view?

I wanted to be able to run a script from a menu, perhaps called 1.Email, and then quickly log into Office365 email to see if any new emails have come in etc.. without having to open Outlook or any other major email client..
100questionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alex GreenProject Systems EngineerCommented:
I have one question, why? I mean you even get a popup with outlook.

Don't bother trying to reinvent the wheel, it'll be longer for you to run the script than it would be if you just opened up outlook and left it open.
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Yes, you can. You use EWS (Exchange Web Services)

After connecting
# Get the Mailbox ID of the Inbox folder.
$inboxFolderID = [Microsoft.Exchange.WebServices.Data.FolderId]::new([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailAddress)

# Bind to the inbox folder.
$boundFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($objExchange,$inboxFolderID)
$boundFolder.UnreadCount

Open in new window

https://stackoverflow.com/questions/44160461/checking-number-of-unread-exchange-mails-with-ews
0
100questionsAuthor Commented:
Thanks Shaun.  And what would be the script to connect then? Or what is before this??
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Shaun VermaakTechnical Specialist/DeveloperCommented:
It is the first part on that link, the section in OP's question
0
100questionsAuthor Commented:
Thanks again Shaun.  Ok, I added credentials etc., however now I don't know where to replace the script you provided or what to remove in order to make it work?
0
100questionsAuthor Commented:
This does not work, I found another solution online.
0
100questionsAuthor Commented:
$mail="email@email.com"
$password="enterpasswordhere"

# Set the path to your copy of EWS Managed API
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
# Load the Assemply
[void][Reflection.Assembly]::LoadFile($dllpath)

# Create a new Exchange service object
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService

#These are your O365 credentials
$Service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials($mail,$password)

# this TestUrlCallback is purely a security check
$TestUrlCallback = {
    param ([string] $url)
    if ($url -eq "https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml") {$true} else {$false}
}
# Autodiscover using the mail address set above
$service.AutodiscoverUrl($mail,$TestUrlCallback)

# create Property Set to include body and header of email
$PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)

# set email body to text
$PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;

# Set how many emails we want to read at a time
$numOfEmailsToRead = 10

# Index to keep track of where we are up to. Set to 0 initially.
$index = 0
# Do/while loop for paging through the folder
do
{
    # Set what we want to retrieve from the folder. This will grab the first $pagesize emails
    $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($numOfEmailsToRead,$index)
    # Retrieve the data from the folder
    $findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$view)
    foreach ($item in $findResults.Items)
    {
        # load the additional properties for the item
        $item.Load($propertySet)

        # Output the results
        "******************************************"
        ""
        "From: $($item.From.Name)"
        ""
        "Subject: $($item.Subject)"
        ""
        #"Body: $($Item.Body.Text)"
        "******************************************"
        ""
        ""
     
    }
    # Increment $index to next block of emails
    $index += $numOfEmailsToRead
} while ($findResults.MoreAvailable) # Do/While there are more emails to retrieve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.