none
Powershell scripting issue RRS feed

  • Question

  • Hey all,

    I'm trying to make a change to my mailboxes as there is an issue with the security on them.

    Get-Mailbox -identity (import from CSV file, Single columb of data) | Add-MailboxPermission -User "domain\svc.qmm" -Deny -AccessRights 'FullAccess

    And

    Get-Mailbox -identity (import from CSV file, Single columb of data) | Add-MailboxPermission -User "domain\svc.qmm" -AccessRights Fullaccess -InheritanceType all

    How do I get the command to pull from a CSV file? I can't figure it out.

    Monday, September 29, 2014 1:09 PM

Answers

  • Hi, you need to look at import-csv and foreach, something along the lines of:

    import-csv C:\yourcsv.csv | % {Get-Mailbox -identity $_.ColumnName | Add-MailboxPermission -User "domain\svc.qmm" -Deny -AccessRights 'FullAccess}


    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:36 PM
    • Unmarked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    Monday, September 29, 2014 1:18 PM
  • That's what I got from there, so, any ideas I just get a >> sign

    >> means that the command is incomplete or waiting for an additional Enter keypress.

    EDIT: You're missing Foreach-Object.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Edited by Mike Laughlin Monday, September 29, 2014 2:22 PM
    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    Monday, September 29, 2014 2:21 PM
  • You missed off the % after the first |. This is needed as it is the symbol for foreach.

    Please try with the %. 

    IE: 

    Import-csv C:\Temp\aliaslist.csv | %{Get-Mailbox -identity $_.Alias | Add-MailboxPermission -User "domain\svc.qmm" -Deny -AccessRights 'FullAccess}

    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    Monday, September 29, 2014 2:25 PM

All replies

  • Hi, you need to look at import-csv and foreach, something along the lines of:

    import-csv C:\yourcsv.csv | % {Get-Mailbox -identity $_.ColumnName | Add-MailboxPermission -User "domain\svc.qmm" -Deny -AccessRights 'FullAccess}


    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:36 PM
    • Unmarked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    Monday, September 29, 2014 1:18 PM
  • OK so that didn't work

    Import-csv C:\Temp\aliaslist.csv | {Get-Mailbox -identity $_.Alias | Add-MailboxPermission -User "domain\svc.qmm" -Deny -AccessRights 'FullAccess}

    That's what I got from there, so, any ideas I just get a >> sign

    Monday, September 29, 2014 2:17 PM
  • That's what I got from there, so, any ideas I just get a >> sign

    >> means that the command is incomplete or waiting for an additional Enter keypress.

    EDIT: You're missing Foreach-Object.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Edited by Mike Laughlin Monday, September 29, 2014 2:22 PM
    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    Monday, September 29, 2014 2:21 PM
  • You missed off the % after the first |. This is needed as it is the symbol for foreach.

    Please try with the %. 

    IE: 

    Import-csv C:\Temp\aliaslist.csv | %{Get-Mailbox -identity $_.Alias | Add-MailboxPermission -User "domain\svc.qmm" -Deny -AccessRights 'FullAccess}

    • Marked as answer by Alexgreen312 Monday, September 29, 2014 2:37 PM
    Monday, September 29, 2014 2:25 PM
  • Ok,


    Import-csv C:\Temp\aliaslist.csv | Foreach {Get-Mailbox -identity $_.Alias | Add-MailboxPermission -User "wsht.local\svc.qmm" -Deny -AccessRights 'FullAccess}

    Would that work? I'm not very good with powershell :(

    Monday, September 29, 2014 2:27 PM
  • Yeah, I did that, it still came up with the >> sign

    Monday, September 29, 2014 2:30 PM
  • You're missing the closing quote on FullAccess:

    Import-csv C:\Temp\aliaslist.csv | ForEach-Object {
    
        Get-Mailbox -identity $_.Alias | Add-MailboxPermission -User 'wsht.local\svc.qmm' -Deny -AccessRights 'FullAccess'
    
    }   


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Monday, September 29, 2014 2:37 PM
  • OK

    I'm really ashamed, I forgot to copy the CSV file to the server. I'll mark answers now.

    Regards

    Alex

    Monday, September 29, 2014 2:37 PM
  • Ok,


    Import-csv C:\Temp\aliaslist.csv | Foreach {Get-Mailbox -identity $_.Alias | Add-MailboxPermission -User "wsht.local\svc.qmm" -Deny -AccessRights 'FullAccess}

    Would that work? I'm not very good with powershell :(

    As Mike says the '>>' means that PowerShell doesn't think you're done. That normally means you're missing either a closing bracket, curly bracket, quotation mark or something else that acts as 'punctuation'.

    As a subtle hint, take a look at your quotation marks.

    Monday, September 29, 2014 2:38 PM
  • OK

    I'm really ashamed, I forgot to copy the CSV file to the server. I'll mark answers now.

    Regards

    Alex

    =]

    No worries, happens to everyone.


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Monday, September 29, 2014 2:39 PM