Announcement

Collapse
No announcement yet.

Powershell Mailbox For-Each query

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Powershell Mailbox For-Each query

    Hi Peeps,

    I am attempting to add a mailbox permission to a bunch of users via the shell.

    This is what I have established so far:

    I have a text file of the SMTP addresses of the users. (c:\users.txt)


    [email protected]
    [email protected]
    [email protected]
    [email protected]

    I ran the command $users = get-content "C:\users.txt" | get-mailbox

    I know I want to use this command:

    $Users | add-mailboxpermission -user "Domain\firstnamelastname -AccessRights FullAcccess

    The problem is the add-mailboxpermission requires the -identity switch first, how do I reference $users?

    I tried a foreach-object but it didn't work, any ideas?

  • #2
    Re: Powershell Mailbox For-Each query

    I managed to get it working, but I can't take the credit:


    $users = get-content "c:\users.txt"

    $users | Get-Mailbox | ForEach-Object {$users1 = $_.distinguishedname; Add-MailboxPermission -Identity $users1 -User "Domain\User" -AccessRights FullAccess}

    Hope this helps someone

    Comment

    Working...
    X