locked
PS script help RRS feed

  • Question

  • I want to add myself to a list of mailboxes here is what I have so far:

    Add-MailboxPermission -Identity jdoe -User me -AccessRights FullAccess

    I want my list inplace of jdoe or can I add a bunch of name here like this -identity jdoe, jsmith, someone else.

    Tuesday, January 17, 2012 10:47 PM

Answers

  • You need to create a CSV file with this format [save it as something like userlist.csv]:

    user
    jdoe
    jsmith
    bspear

    Then you need a script that will read the CSV file and perform the 'add-mailboxpermission' command like this:

    import-csv c:userlist.csv | foreach-object {
       Add-MailboxPermission -Identity $_.user <admin> -AccessRights FullAccess
    }

    That should do what you want.


    JAUCG
    Wednesday, January 18, 2012 1:42 AM
  • The approach above is definitely the better approach if you've got a fair number of names to run through. If you have a small number - my threshold is 10 or less, you can get by with an array as shown below - it just involves one extra statement:

    • $names = ('user1', 'user2', 'user3')
    • foreach ($name in $names) { Add-MailboxPermission -Identity $name -User you -AccessRights FullAccess }

    Just a handy alternative if you're like me and can't be bothered creating files for the smaller batch runs (which we often get in Helpdesk-style calls).

    Cheers,
    Lain

    • Marked as answer by rkassing Wednesday, January 18, 2012 2:19 PM
    Wednesday, January 18, 2012 2:29 AM
  • Blame it on slipshod Powershell scripts: [missed the one word which is bolded in the script now]

    import-csv c:userlist.csv | foreach-object {
        Add-MailboxPermission -Identity $_.user -user <admin acct> -AccessRights FullAccess
    }

    Sorry about that!


    JAUCG
    • Marked as answer by rkassing Thursday, January 19, 2012 2:21 PM
    Thursday, January 19, 2012 2:19 PM

All replies

  • You need to create a CSV file with this format [save it as something like userlist.csv]:

    user
    jdoe
    jsmith
    bspear

    Then you need a script that will read the CSV file and perform the 'add-mailboxpermission' command like this:

    import-csv c:userlist.csv | foreach-object {
       Add-MailboxPermission -Identity $_.user <admin> -AccessRights FullAccess
    }

    That should do what you want.


    JAUCG
    Wednesday, January 18, 2012 1:42 AM
  • The approach above is definitely the better approach if you've got a fair number of names to run through. If you have a small number - my threshold is 10 or less, you can get by with an array as shown below - it just involves one extra statement:

    • $names = ('user1', 'user2', 'user3')
    • foreach ($name in $names) { Add-MailboxPermission -Identity $name -User you -AccessRights FullAccess }

    Just a handy alternative if you're like me and can't be bothered creating files for the smaller batch runs (which we often get in Helpdesk-style calls).

    Cheers,
    Lain

    • Marked as answer by rkassing Wednesday, January 18, 2012 2:19 PM
    Wednesday, January 18, 2012 2:29 AM
  •  

    Just a handy alternative if you're like me and can't be bothered creating files for the smaller batch runs (which we often get in Helpdesk-style calls).

     


    Happens to me all the time.  Mostly I get a list of names or accounts in an email. 

    If you're running the V3 ISE, you can use this to create an array directly from a list copied to your clipboard:

    http://mjolinor.wordpress.com/2011/12/31/clip-toarray-for-ps-v3-ise/?preview=true&preview_id=156&preview_nonce=6fbb13253a

     


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Wednesday, January 18, 2012 2:56 AM
  • jaucg,

    What is the -identity going to be?

    • Edited by rkassing Wednesday, January 18, 2012 2:24 PM
    Wednesday, January 18, 2012 2:20 PM
  • In the example JAUCG provided, the Identity is coming from the input file. They have provided an example of what the file should look like, so to use that example:

    • The first line us just the word "User" which acts both as a header and an instruction for Import-Csv to create an attribute on the input object named the same thing (User).
    • Every line after that is just the Identity of the mail user you wish to modify. There's only one user per line and nothing else needs to go on that line.

    Cheers,
    Lain

    Wednesday, January 18, 2012 2:31 PM
  • What is telling it to look in the file?

    Wednesday, January 18, 2012 2:49 PM
  • These three lines of code from their example:

    import-csv c:userlist.csv | foreach-object {
        Add-MailboxPermission -Identity $_.user <admin> -AccessRights FullAccess
    }

    Cheers,
    Lain

    Wednesday, January 18, 2012 2:57 PM
  • I keep getting this error when I run the above script.

    Add-MailboxPermission : Cannot bind parameter 'Identity'. Cannot convert the "@
    {user=akelley}" value of type "System.Management.Automation.PSCustomObject" to
    type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter".
    At C:\users\rkassing\documents\scripts\Full_rights.ps1:2 char:36
    +     Add-MailboxPermission -Identity <<<<  $_ -user 'rkassing' -AccessRights F
    ullAccess
        + CategoryInfo          : InvalidArgument: (:) [Add-MailboxPermission], Pa
       rameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchang
       e.Management.RecipientTasks.AddMailboxPermission

     

    Can someone tell me what I am doing wrong?

     

    Wednesday, January 18, 2012 5:13 PM
  • Perhaps try this alternative:
    foreach ($name in (Import-Csv -Path D:\Temp\names.csv)) {
      Add-MailboxPermission -Identity $name -User <admin> -AccessRights FullAccess
    }
    

    Obviously you'd change the path in the first line to point to your own file. Again, the file structure is very simple and would look like the following:
    User
    username1
    username2
    User, in this instance, is just a header for the file, not an actual username so it is ignored in the script.
    Cheers,
    Lain
    Thursday, January 19, 2012 4:33 AM
  • Blame it on slipshod Powershell scripts: [missed the one word which is bolded in the script now]

    import-csv c:userlist.csv | foreach-object {
        Add-MailboxPermission -Identity $_.user -user <admin acct> -AccessRights FullAccess
    }

    Sorry about that!


    JAUCG
    • Marked as answer by rkassing Thursday, January 19, 2012 2:21 PM
    Thursday, January 19, 2012 2:19 PM