Announcement

Collapse
No announcement yet.

Exchange 2007 powershell script help

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

  • Exchange 2007 powershell script help

    Hi

    I would be very grateful if someone could help me complete this script ive tried to create below. I just want to grant multiple users full access and send as permissions to several different mailboxes in exchange 2007.

    $data = import-csv C:\Users\admin-me\Desktop\scripts\exchange\grantfullmailboxpermis sions\mailboxes.csv
    foreach ($line in $data) {Add-MailboxPermission $line.MailboxName $line.userPrincipalName -AccessRights FullAccess -InheritanceType all}

    My mailboxes.csvincludes two columns one for the actual mailbox name and the other for users id

    Any help would be gratefully received

  • #2
    Re: Exchange 2007 powershell script help

    Try this

    Code:
    $data = import-csv C:\Users\admin-me\Desktop\scripts\exchange\grantfullmailboxpermissions\mailboxes.csv 
    foreach ($line in $data) {Add-MailboxPermission -Identity $line.MailboxName -User $line.userPrincipalName -AccessRights FullAccess -InheritanceType all}
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Exchange 2007 powershell script help

      Thanks Jeremy

      Although I gave that a try and had error

      "unexpected token 'in' expression or statement line 1: char 127

      Thanks

      Comment


      • #4
        Re: Exchange 2007 powershell script help

        Are you sure the command you're running is the same as you posted? There's only 104 characters in the first line and your error says it occurred at the 127th character.

        You may want to add the double quotes (e.g. "C:\path\cvs.csv") around your csv path...
        Regards,
        Jeremy

        Network Consultant/Engineer
        Baltimore - Washington area and beyond
        www.gma-cpa.com

        Comment


        • #5
          Re: Exchange 2007 powershell script help

          Hi Jeremy

          I can confirm I have the following. The admin username was changed, hence reason for extra / less characters on line 1

          $data = import-csv "C:\Users\admin-me\Desktop\scripts\exchange\grantfullmailboxpermis sions\mailboxes.csv" foreach ($line in $data) {Add-MailboxPermission -Identity $line.MailboxName -User $line.userPrincipalName -AccessRights FullAccess -InheritanceType all}
          Any other ideas to get this script working?

          Would I need to specify which mail server for example mail-a or mail-b, depending upon which mailbox I want to grant full access to? Or would that not matter

          Thanks

          Comment


          • #6
            Re: Exchange 2007 powershell script help

            You need to have two lines in your script. One to import the CSV and the other to loop through it. Make sure the foreach is on a second line.

            Code:
            $data = import-csv "C:\Users\admin-me\Desktop\scripts\exchange\grantfullmailboxpermissions\mailboxes.csv" 
            foreach ($line in $data) {Add-MailboxPermission -Identity $line.MailboxName -User $line.userPrincipalName -AccessRights FullAccess -InheritanceType all}
            Regards,
            Jeremy

            Network Consultant/Engineer
            Baltimore - Washington area and beyond
            www.gma-cpa.com

            Comment


            • #7
              Re: Exchange 2007 powershell script help

              Got two lines as requested, but still getting the same error?

              I have tried via running exchange powershell copy and paste and also via ps script, neither seem to work for some strange reason

              Would this script need to be run directly on the exchange server, or should it also client (windows vista) PC via exchange powershell or ps

              Comment


              • #8
                Re: Exchange 2007 powershell script help

                You will need the Exchange management tools installed on whatever system you're running it from. You'll also need to add the Exchange PS Snapin if you're not running the script in the EMS.

                http://technet.microsoft.com/en-us/l...exchg.80).aspx
                Regards,
                Jeremy

                Network Consultant/Engineer
                Baltimore - Washington area and beyond
                www.gma-cpa.com

                Comment


                • #9
                  Re: Exchange 2007 powershell script help

                  No joy

                  Cant seem to get the script working, same errors as the original post

                  Almost given up hope

                  Comment


                  • #10
                    Re: Exchange 2007 powershell script help

                    Can you post the first few lines of your CSV file (include headers as they are but sanitise names if you need to)?
                    Are you running the script on your Exchange box?
                    Please post the full error message as a screen shot
                    Tom Jones
                    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                    PhD, MSc, FIAP, MIITT
                    IT Trainer / Consultant
                    Ossian Ltd
                    Scotland

                    ** Remember to give credit where credit is due and leave reputation points where appropriate **

                    Comment


                    • #11
                      Re: Exchange 2007 powershell script help

                      Hi

                      running script below as is which is saved as mailboxes.ps1

                      $data = import-csv "C:\Users\admin-bongoa\Desktop\scripts\exchange\grantfullmailboxpe rmissions\mailboxes.csv"
                      foreach ($line in $data) {Add-MailboxPermission -Identity $line.MailboxName $line.userPrincipleName -AccessRights FullAccess -InheritanceType all}
                      remove-variable data
                      remove-variable line



                      ERROR

                      [PS] C:\Users\admin-bongoa\Desktop>./mailboxes
                      Add-MailboxPermission : A positional parameter cannot be found that accepts arg
                      ument '$null'.
                      At C:\Users\admin-bongoa\Desktop\mailboxes.ps1:2 char:48
                      + foreach ($line in $data) {Add-MailboxPermission <<<< -Identity $line.Mailbox
                      Name $line.userPrincipleName -AccessRights FullAccess -InheritanceType all}remo
                      ve-variable data
                      + CategoryInfo : InvalidArgument: ( [Add-MailboxPermission], Pa
                      rameterBindingException
                      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Exchange.M
                      anagement.RecipientTasks.AddMailboxPermission


                      The spreadsheet CSV file looks like this (Although displayed in two columns, doesnt show that properly on here)

                      MailboxName sAMAccountName
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain LOCAL\MarchE
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain-LOCAL\MorganR10
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain-LOCAL\DuffyL
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain-LOCAL\McGowaS
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain-LOCAL\Samuelc
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain-LOCAL\Austins
                      CN=HrMCA,OU=Accounts,OU=Domain,DC=domain,DC=local Domain-LOCAL\JonesM8

                      Comment


                      • #12
                        Re: Exchange 2007 powershell script help

                        OK, I've spotted a typo in the main line of code:
                        foreach ($line in $data) {Add-MailboxPermission -Identity $line.MailboxName $line.userPrincipalName -AccessRights FullAccess -InheritanceType all}

                        Also if you check the help for the cmdlet
                        http://technet.microsoft.com/en-us/l...exchg.80).aspx
                        it requires 5 mandatory parameters which I am not sure if you are supplying
                        Tom Jones
                        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                        PhD, MSc, FIAP, MIITT
                        IT Trainer / Consultant
                        Ossian Ltd
                        Scotland

                        ** Remember to give credit where credit is due and leave reputation points where appropriate **

                        Comment


                        • #13
                          Re: Exchange 2007 powershell script help

                          All is becoming clear.

                          1. You need to add the snapin for Exchange at the beginning of your script. See my post above with the link to Technet.

                          2. The format of your CSV is wrong. The MailboxName column should be the alias or display name of the mailbox. You have the DN of the user of mailbox listed. The sAMAccountName should be fine but drop the domain from that field. (e.g. "user" not "domain\user")

                          3. Your script is not referencing columns that exist. Either change the script to match the columns or change the columns to match the script. (i.e. the script is using UserPrincipleName and the CSV is using sAMAccountName)

                          Post back with any questions you have on that.
                          Regards,
                          Jeremy

                          Network Consultant/Engineer
                          Baltimore - Washington area and beyond
                          www.gma-cpa.com

                          Comment


                          • #14
                            Re: Exchange 2007 powershell script help

                            Originally posted by Ossian View Post
                            it requires 5 mandatory parameters which I am not sure if you are supplying
                            I think the URL is misleading. Check the examples. At minimum it needs the identity and user.
                            Regards,
                            Jeremy

                            Network Consultant/Engineer
                            Baltimore - Washington area and beyond
                            www.gma-cpa.com

                            Comment


                            • #15
                              Re: Exchange 2007 powershell script help

                              OK, I just looked at the parameter list and 5 were marked as "required", but the example gives 4.

                              Too many other things on to look in more detail!
                              Tom Jones
                              MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                              PhD, MSc, FIAP, MIITT
                              IT Trainer / Consultant
                              Ossian Ltd
                              Scotland

                              ** Remember to give credit where credit is due and leave reputation points where appropriate **

                              Comment

                              Working...
                              X