The script below does not run it just hangs at the very end inside the powershell console it does however work in the ISE. I have made sure to load all the assemblies,snapins, and modules into the console. Also tried -sta mode and runas admin still hangs at the very end.
[void] [Reflection.Assembly]::LoadWithPartialName("Framework64")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.PowerShell.ISECommon")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Management.Automation")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.PowerShell.GPowerShell")
[void] [Reflection.Assembly]::LoadWithPartialName("System.ComponentModel.Composition")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.PowerShell.Editor")
[void] [Reflection.Assembly]::LoadWithPartialName("PresentationFramework")
[void] [Reflection.Assembly]::LoadWithPartialName("WindowsBase")
[void] [Reflection.Assembly]::LoadWithPartialName("PresentationCore")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Xaml")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Configuration")
[void] [Reflection.Assembly]::LoadWithPartialName("UIAutomationProvider")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Management")
[void] [Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Numerics")
[void] [Reflection.Assembly]::LoadWithPartialName("PresentationFramework.Aero")
[void] [Reflection.Assembly]::LoadWithPartialName("UIAutomationTypes")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Transactions")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.PowerShell.GraphicalHost")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.CSharp")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Data")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Runtime.DurableInstancing")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Outlook")
[void] [Reflection.Assembly]::LoadWithPartialName("office")
[void] [Reflection.Assembly]::LoadWithPartialName("CustomMarshalers")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.WSMan.Management")
[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.WSMan.Runtime")
#you'll get a popup in outlook at this point where you pick the folder you want to scan
$f = $n.pickfolder()
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)
$a = $f.Items
$b = $a.Count
$objShell = new-object -com shell.application
$d=$objShell.BrowseForFolder(0,"Title",0,"c:\")
$c= $d.self
$path=$c.path
#now loop through them and grab the attachments
foreach ($item in $a)
{ foreach ($attach in $item.Attachments)
{ if ($item.ReceivedTime -gt (get-date).AddDays(-30))
{if ($attach.filename.contains("pdf")){ $attach.saveasfile((Join-Path $path $attach.filename))
}
elseif ($attach.filename.contains("docx"))
{ $attach.saveasfile((Join-Path $path $attach.filename))
}
}
}
}