locked
[PS] Get-Mailbox error RRS feed

  • Question

  • I have this get-mailbox script to get mailbox information from a csv file.

    $users = import-csv c:\temp\user.csv
    @(foreach ($user in $users) { get-mailbox $user.samaccountname }
    )

    user.csv content is just 1 user, e.g:

    user

    user1

    but when the script is executed, it will list down all the users in the entire organization.

    [PS] C:\TEMP>$users = import-csv user.csv
    [PS] C:\TEMP>@(foreach ($user in $users) { get-mailbox $user.samaccountname }
    >> )
    >>
    
    Name                      Alias                ServerName       	ProhibitSendQuota
    ----                      -----                ----------       	-----------------
    adm-ExcAdmin              adm-ExcAdmin         exc.realestate.net   Unlimited
    DiscoverySearchMailbox... DiscoverySearchMa... exc.realestate.net   50 GB (53,687,091,200 bytes)
    user1                     user1                exc.realestate.net   Unlimited
    user2                     user2                exc.realestate.net   Unlimited
    user3                     user3                exc.realestate.net   Unlimited
    
    
    [PS] C:\TEMP>

    content of $users verified as follows:

    [PS] C:\TEMP>$users
    
    user
    ----
    user1
    
    
    [PS] C:\TEMP>

    Why is it listing all other users, and not the one that I wanted in user.csv?

    Thanks in advanced for helping!


    Saturday, March 18, 2017 7:32 PM

Answers

  • your csv column name is not samaccountname?

    get-mailbox $user.user

    • Edited by Jon.Knight Saturday, March 18, 2017 7:59 PM
    • Proposed as answer by Jason.Chao Monday, March 20, 2017 6:05 AM
    • Marked as answer by Raymond Tusk Monday, March 20, 2017 4:29 PM
    Saturday, March 18, 2017 7:58 PM
  • The column heading in your file is "user", so as Jon.Knight suggests you must use $user.user.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    • Marked as answer by Raymond Tusk Monday, March 20, 2017 4:29 PM
    Sunday, March 19, 2017 4:38 AM

All replies

  • your csv column name is not samaccountname?

    get-mailbox $user.user

    • Edited by Jon.Knight Saturday, March 18, 2017 7:59 PM
    • Proposed as answer by Jason.Chao Monday, March 20, 2017 6:05 AM
    • Marked as answer by Raymond Tusk Monday, March 20, 2017 4:29 PM
    Saturday, March 18, 2017 7:58 PM
  • it is!
    Saturday, March 18, 2017 8:27 PM
  • The column heading in your file is "user", so as Jon.Knight suggests you must use $user.user.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    • Marked as answer by Raymond Tusk Monday, March 20, 2017 4:29 PM
    Sunday, March 19, 2017 4:38 AM
  • Thanks Ed and Jon!

    I didn't get it at first.

    changed to 

    $users = import-csv c:\temp\user.csv
    @(foreach ($user in $users) {get-mailbox $user.SamAccountName}
    )
    
    

    and the content of csv to

    [PS] C:\TEMP>$users
    
    SamAccountName
    --------------
    user1

    and now it works!

    Sunday, March 19, 2017 8:22 AM
  • Please feel free to mark responses as the answer and/or vote them helpful as appropriate.

    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Celebrating 20 years of providing Exchange peer support!

    Sunday, March 19, 2017 6:55 PM