1

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

1 Answer 1

1

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
    }

}
Sign up to request clarification or add additional context in comments.

1 Comment

it's working :) Ia have another question. -TargetRootFolder is now $_.Name and the name of folder is Archive.pst. How can I remove .pst in the name? Is It possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.