Powershell Export-Mailbox -PSTFolderPath

Pellfrischmann
Pellfrischmann used Ask the Experts™
on
I would like to export a range off mailboxes to different variable folders i.e. c:\test\username\username.pst with out having to create a script for each user.

I have managed to get a script which looks up the mailboxes in a group and then exports to a specified location however I cannot get it to export to a folder variable using username and put the pst file inside this.

Get-user | where { $_.office -Eq "IT Services1" } | Export-Mailbox -PSTFolderPath ("C:\test\") -confirm:$false

Any help would be greatly appreciated.

Thanks

John
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
i don't think you need to do this as every pst file will get exported will have its mailbox alies which is uniqe

Author

Commented:
Thats is correct however I would like it to put the pst file it a folder which is called the username i.e. c:\test\john\john.pst

But has the command looks up several email addresses so I need to use a variable to do this.

Commented:
Try this :

Get-user | where { $_.office -Eq "IT Services1" } |  [string]$drive = "c:\test\" + $_.name; md $drive;Export-Mailbox -PSTFolderPath ($drive) -confirm:$false
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
Thanks but I get the following error.

Expressions are only permitted as the first element of a pipeline.
At c:\test\test3.ps1:1 char:91
+ Get-user | where { $_.office -Eq "IT Services1" } |  [string]$drive = "c:\tes
t\" + $_.name; <<<<  md $drive;Export-Mailbox -PSTFolderPath ($drive) -confirm:
$false

Commented:
sorry this one should work:

Get-user | where { $_.office -Eq "IT Services1" } |  %{[string]$drive = "c:\test\" + $_.name; md $drive;Export-Mailbox -PSTFolderPath ($drive) -confirm:$false}

Author

Commented:
Thanks again, nearly works as it creates the folder but then asks for the identity if typed in works fine

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\test


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        17/07/2009     17:09            John Smith

cmdlet Export-Mailbox at command pipeline position 1
Supply values for the following parameters:
Identity:
Commented:
Just add "-identity $_.name" just after export-mailbox

Author

Commented:
Thanks very much for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial