Question

I need a help with this script.

$data = Import-CSV C:\temp\import.csv
ForEach ($i in $data){
$pstpath = "\\server\pst$\" + $i.folder + "\"
$user = $i.user
$folder = $i.folder
Get-ChildItem -Recurse -path $pstpath -Filter *.pst | New-MailboxImportRequest -FilePath "$pstpath + $_.name" - Mailbox $user -Name "Import $user $_.name" -BadItemLimit 30 -ConflictResolutionOption KeepAll -TargetRootFolder $_.name -IsArchive -confirm: $false

}

I've got this error for each pst in folder:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline in put or the input and its properties do not match any of the parameters that take pipeline input. + CategoryInfo : InvalidArgument: (archive.pst:PSObject) [New-MailboxImportRequest], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,New-MailboxImportRequest

Was it helpful?

Solution

Looks like the New-MailboxImportRequest cmdlet doesn't accept pipeline input, and if it did you's have to remove the '-FilePath "$pstpath + $_.name"' part from the command.

Try this instead:

$data = Import-CSV C:\temp\import.csv
ForEach ($i in $data){

    $user = $i.user
    $folder = $i.folder
    $pstpath = "\\server\pst$\$folder"

    Get-ChildItem -Recurse -path $pstpath -Filter *.pst | Foreach-Object{
        New-MailboxImportRequest -FilePath $_.FullName - Mailbox $user -Name "Import $user $($_.Name)" -BadItemLimit 30 -ConflictResolutionOption KeepAll -TargetRootFolder $_.Name -IsArchive -Confirm:$false
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top