I’m new to the scene of PS & have been thrown in the deep end, from my perspective, as I don’t done PS at all & just beginning out with it.
I require help. I need to write a script that will go off to get the latest email from a specific account, then output the content to a csv, or assigned to variables.
Desktop Outlook - you’d have to use the Outlook DOM (Document Object Model) with PowerShell and DCOM
Enterprise Exchange - you’d have to leverage the EWS API.
Postanote is correct. If you’re talking about Exchange/Outlook, a simple command will not do the job. Those will only get you topical information about a message (sender, recipient, message subject, etc). This requires a little fancy footwork using Exchange EWS or Outlook Interop Assemblies that can dig deep into an email.
After some digging around. I found bits & pieces that i that would resolve my issue.
Please forgive my coding. I’ve currently got it to output to the host, just to check if it works. To which after some testing, i can say this works for me.
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace(“MAPI”)
$folder=$namespace.GetDefaultFolder(6)
$folder.Items | #Select Email with matching subject line
?{$.subject -match “New User Request” } |
sort receivedtime -desc |
%{
echo $.body #do stuff with body
Sets what to collect from the Email
$RE = [RegEx]‘(?sm)FirstName:\s+(?<FirstName>.?)$.?LastName:\s+(?<LastName>.?)$.?Location\s*:\s*(?<Location>.?)$.Role:\s+(?<Role>.?)$.?Manager:\s+(?<Manager>.?)$.?’ #Collects User From Email
ForEach ($item in $inbox.items){