You need to use the findFolder method to first find the root subfolder and then you use that folderid to find the subfolders of it (the same as you have above) and then you need to query each child folder to get its items. To Get the initial sub-folder you can use something like the folder eg in you context you would run it like
$Subfolder = Get-FolderFromPath -MailboxName [email protected] -FolderPath InboxProcess -service $service
function Get-FolderFromPath {
param (
[Parameter(Position = 0, Mandatory = $true)] [string]$FolderPath,
[Parameter(Position = 1, Mandatory = $true)] [string]$MailboxName,
[Parameter(Position = 2, Mandatory = $true)] [Microsoft.Exchange.WebServices.Data.ExchangeService]$service
)
process {
## Find and Bind to Folder based on Path
#Define the path to search should be seperated with
#Bind to the MSGFolder Root
$psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$PidTagMessageSizeExtended = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0xe08, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long);
$PR_ATTACH_ON_NORMAL_MSG_COUNT = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x66B1, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);
$psPropset.Add($PidTagMessageSizeExtended)
$psPropset.Add($PR_ATTACH_ON_NORMAL_MSG_COUNT)
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root, $MailboxName)
$tfTargetFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderid)
#Split the Search path into an array
$fldArray = $FolderPath.Split("")
if ($fldArray.Length -lt 2) {throw "No Root Folder"}
#Loop through the Split Array and do a Search for each level of folder
for ($lint = 1; $lint -lt $fldArray.Length; $lint++) {
#Perform search based on the displayname of each folder level
$fvFolderView = new-object Microsoft.Exchange.WebServices.Data.FolderView(1)
$fvFolderView.PropertySet = $psPropset
$SfSearchFilter = new-object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName, $fldArray[$lint])
$findFolderResults = $service.FindFolders($tfTargetFolder.Id, $SfSearchFilter, $fvFolderView)
$tfTargetFolder = $null
if ($findFolderResults.TotalCount -gt 0) {
foreach ($folder in $findFolderResults.Folders) {
$tfTargetFolder = $folder
}
}
else {
Write-host ("Error Folder Not Found check path and try again") -ForegroundColor Red
$tfTargetFolder = $null
break
}
}
if ($tfTargetFolder -ne $null) {
$tfTargetFolder | Add-Member -Name "FolderPath" -Value $FolderPath -MemberType NoteProperty
$tfTargetFolder | Add-Member -Name "Mailbox" -Value $MailboxName -MemberType NoteProperty
$prop4Val = $null
if ($tfTargetFolder.TryGetProperty($PidTagMessageSizeExtended, [ref] $prop4Val)) {
Add-Member -InputObject $tfTargetFolder -MemberType NoteProperty -Name FolderSize -Value $prop4Val
}
$prop5Val = $null
if ($tfTargetFolder.TryGetProperty($PR_ATTACH_ON_NORMAL_MSG_COUNT, [ref] $prop5Val)) {
Add-Member -InputObject $tfTargetFolder -MemberType NoteProperty -Name PR_ATTACH_ON_NORMAL_MSG_COUNT -Value $prop5Val
}
return, [Microsoft.Exchange.WebServices.Data.Folder]$tfTargetFolder
}
else {
return, $null
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…