I have a powershell script I used a while back for Outlook 2007, it read emails, wrote them to a custom event log, and then deleted the email.
I'm trying to resurect this script to work with outlook 2010, however its not being too cooperative.
This is the script
$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)
$inbox.items | foreach {
if($_.SenderEmailAddress -match "Reporter@company.com")
{
$MessageBody = $_.body
write-eventlog -logname OpsCenter -Source 'USDReporter' -Entrytype Error -EventID 4001 -Message $MessageBody
$_.delete()
}
ElseIf($_.SenderEmailAddress -match "admin@company.com")
{
$MessageBody = $_.body
write-eventlog -logname OpsCenter -Source 'Database Datascantech' -Entrytype Error -EventID 4001 -Message $MessageBody
$_.delete()
}
}
The error that I'm getting is
new-object : Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046}
failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).
At C:\Scripts\ScomEmailAlerts.ps1:2 char:12
+ $outlook = new-object -com outlook.application;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At C:\Scripts\ScomEmailAlerts.ps1:3 char:1
+ $ns = $outlook.GetNameSpace("MAPI");
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Paul Arbogast