can someone provide a way I can run this script to key on the members of a distribution group instead of all mailboxes.

$users = Get-Mailbox –ResultSize Unlimited

ForEach ($u in $users)
     New-MailboxImportRequest –Mailbox $u –FilePath \\nas01\backup-new.pst -IncludeFolders “#Calendar#”

Open in new window

Who is Participating?
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That probably means to use
$users = Get-DistributionGroupMember YourDistGroup | Get-Mailbox 

Open in new window

Maybe this shorter code works without using a foreach loop:
Get-DistributionGroupMember YourDistGroup | Get-Mailbox |
  New-MailboxImportRequest –FilePath \\nas01\backup-new.pst -IncludeFolders “#Calendar#”

Open in new window


You'll first have to retrieve all individual members using Get-DistributionGroupMember [groupname].

So this would probably do what you want:

$members = Get-DistibutionGroupName [groupname]

foreach ($member in $members) {
New-MailboxImportRequest -Mailbox $member.Name -FilePath \\nas01\backup-new.pst -IncludeFolders "#Calendar#"

Open in new window

Hope this helps.


siber1Author Commented:
thank you so much Qlemo, I wa missing the |get-mailbox  - that worked perfectly.
the shorter code didn't work, but the first suggestion and passing the variable worked exactly as needed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.