Hi,
I have a main script in which I have a custom collection where I will be storing config information andOutlook COM Object.
I'm passing the custom collection's object as a parameter to the background jobs.
I'm getting the exception "Property .. cannot be found on this object; make sure it exists and is settable" when I try to access the Outlook COM Object's properties present in the custom collection.
I can access the properties and methods of the Outlook object in the main script but not in the background jobs.
Below is the code.
$PFServerList = @()
$csv = Import-Csv 'C:\Config.csv'
foreach ($line in $csv)
{
$TempObj = New-Object System.Object
$TempObj | Add-Member -type NoteProperty -name PFRoot -value $line.PFRoot
$TempObj | Add-Member -type NoteProperty -name PFPath -value $line.PFPath
$TempObj | Add-Member -type NoteProperty -name PFfolder -value null # Outlook COM Object will be stored
$TempObj | Add-Member -type NoteProperty -name PostSubject -value $null
$PFServerList += $TempObj
}
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
for($i = 0;$i -lt $PFServerList.Count; $i++)
{
$namespace = $outlook.GetNameSpace("MAPI")
$session = $namespace.session
$Pfs = $namespace.folders | where {$_.name -like "Public FOlders*"}
$APF = $pfs.folders | where {$_.name -eq "All Public Folders"}
$Pflist = $PFServerList[$i].PFPath.split("\")
$PFlist = $pflist | ?{$_}
$PFfolder = $APF.folders.Item($PFServerList[$i].PFRoot)
foreach($pf in $Pflist)
{
$PFfolder = $PFfolder.folders.item($pf)
}
$PFServerList[$i].PFfolder = $PFfolder
}
$PostMessage=
{
param($PFServer)
try
{
$post_item = $PFServer.PFfolder.items.add(6)
$post_subject = "Test Client MAPI"
$post_item.Subject = $post_subject # I get exception here when I try to access $post_item.Subject
# Remaining code
}
catch
{
}
}
for($i = 0;$i -lt $PFServerList.Count; $i++)
{
Start-Job -ScriptBlock $PostMessage -ArgumentList $PFServerList[$i]
}
Where have I gone wrong?
Thanks,
Ashrith