Export of Mailbox subfolders failing – Value is invalid
Hi, I have the script below that is supposed grab statistics on Archive/Cabinet to run through a fetch all folders in a “Cabinet” folder then run a loop for each folder under Cabinet so the folder can be exported to its own PST file located on the same server. I have tried many things and I cannot seem to get the passed the error “The provided IncludeFolders or ExcludeFolders value is invalid. Folder path ‘/Cabinet/Subfolder’ is invalid. What am I missing here?
Script
# Define variables for the mailbox and the root folder from which subfolders will be exported
$Mailbox = “Archive” # Replace with the mailbox you want to export
$RootFolder = “Cabinet” # Replace with the folder you want to export subfolders from
$ExportPath = “\ServernameM$exports” # Replace with the path where you want the PST files to be saved
# Get a list of subfolders under the specified root folder
$Subfolders = Get-MailboxFolderStatistics -Identity $Mailbox | Where-Object { $_.FolderPath -like “/$RootFolder/*” }
# Loop through each subfolder and create a New-MailboxExportRequest for each
foreach ($Subfolder in $Subfolders) {
# Get the subfolder name and replace any illegal characters in file names
$FolderName = $Subfolder.Name -replace ‘[\/:*?”<>|]’, ‘_’
$PSTFilePath = “$ExportPath$FolderName.pst”
# Create the mailbox export request for the subfolder
New-MailboxExportRequest -Mailbox $Mailbox -FilePath $PSTFilePath -IncludeFolders “$($Subfolder.FolderPath)”
Write-Host “Export request created for $($Subfolder.FolderPath) to $PSTFilePath”
}
Hi, I have the script below that is supposed grab statistics on Archive/Cabinet to run through a fetch all folders in a “Cabinet” folder then run a loop for each folder under Cabinet so the folder can be exported to its own PST file located on the same server. I have tried many things and I cannot seem to get the passed the error “The provided IncludeFolders or ExcludeFolders value is invalid. Folder path ‘/Cabinet/Subfolder’ is invalid. What am I missing here?Script# Define variables for the mailbox and the root folder from which subfolders will be exported$Mailbox = “Archive” # Replace with the mailbox you want to export$RootFolder = “Cabinet” # Replace with the folder you want to export subfolders from$ExportPath = “\ServernameM$exports” # Replace with the path where you want the PST files to be saved# Get a list of subfolders under the specified root folder$Subfolders = Get-MailboxFolderStatistics -Identity $Mailbox | Where-Object { $_.FolderPath -like “/$RootFolder/*” }# Loop through each subfolder and create a New-MailboxExportRequest for eachforeach ($Subfolder in $Subfolders) {# Get the subfolder name and replace any illegal characters in file names$FolderName = $Subfolder.Name -replace ‘[\/:*?”<>|]’, ‘_’$PSTFilePath = “$ExportPath$FolderName.pst”# Create the mailbox export request for the subfolderNew-MailboxExportRequest -Mailbox $Mailbox -FilePath $PSTFilePath -IncludeFolders “$($Subfolder.FolderPath)”Write-Host “Export request created for $($Subfolder.FolderPath) to $PSTFilePath”} Read More