Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Powershell - List the folders of a pst file

$
0
0

Hello,

I'm working on a VERY large pst file project, I want to verify they can be opened by going pst by pst and opening them.  Doing it manually.. sucks..  we are talking 27,000 pst files.

I have 

#######################################################################
# function: check-error                                               #
#    Checks to see if there is anything in the error var.  If so we   #
#    log it                                               #
#######################################################################
function check-error
{param([string]$msg)
if($Error)
{
Write-Host -ForegroundColor Red $msg
Write-Host -ForegroundColor Red $($Error[0].exception)
$errorfiles += $msg
}
} #END check-error

$errorfiles = @()

$outlook = new-object -com Outlook.Application
$inbox = $outlook.Session.GetDefaultFolder(6)




$ol = new-object -com outlook.application 
$ns = $ol.getNamespace("MAPI") 
$ns.AddStore("\\server\share\user.pst") 


#specify outlook com
$outlook = New-Object -ComObject Outlook.Application 
#using mapi
$namespace = $outlook.getnamespace("MAPI") 
#path to pst file
$PSTPath = "\\server\share\user.pst"
#PST Display name
$PSTDisplayName = "Personal Folders"
#add pst to outlook
$namespace.AddStore($PSTPath)
check-error -msg "$pstpath"
SLEEP 3

#remove pst from outlook
$PSTFolder = $Namespace.Folders.Item($PSTDisplayName) 
$Namespace.GetType().InvokeMember('RemoveStore',[System.Reflection.BindingFlags]::InvokeMethod,$null,$Namespace,($PSTFolder)) 

This will get the file, open it in Outlook, and remove it from outlook, but I want to verify that it isn't corrupt by accessing the inbox, maybe getting the first 5 emails in the inbox in the pst etc..  if we can't I would log it.  I'm having a hard time figuring out how to access the internals of a pst file.


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>