Exchange scripting, How do I reference a .csv instead of a username

Stefan Diedericks 125 Reputation points
2023-02-06T09:16:22.6366667+00:00

What would be the correct format ( do I only need the userprinciplename?) as well as referencing the script.

For example, how would I give a list of users instead of one user at a time

Set-Mailbox -Identity "Debra Garcia" -MaxSendSize 25mb -MaxReceiveSize 35mb

Thank you in advance

Microsoft Exchange Online
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,177 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,058 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 95,341 Reputation points MVP
    2023-02-06T09:30:22.19+00:00

    Assuming you have a "blabla.csv" file with column ID,UserPrincipalName,Email, you can do something like this:

    Import-CSV blabla.csv | % { Set-Mailbox -Identity $_.ID -MaxSendSize 25mb -MaxReceiveSize 35mb }

    where we are referencing the first column of the CSV and for each of its values, running the Set-Mailbox cmdlet against the corresponding user. Thus, it's important to have proper values for the ID column, not only values that actually exists in the tenant, but such that uniquely identify a given user/mailbox. This is the reason why we usually recommend to use something like the UPN, or the objectID. Other values, such as an email address or even display name can also work, but don't guarantee uniqueness, and thus might cause the cmdlet to fail.

    Anyway, this is how you can use for example an "Email" column - all you need to do is reference it:

    Import-CSV blabla.csv  | % { Set-Mailbox -Identity $_.ID -MaxSendSize 25mb -MaxReceiveSize 35mb }
    
    

    You don't need to have all three columns in the CSV either, that's just for the sake of example.

    0 comments No comments

  2. Aholic Liang-MSFT 13,741 Reputation points Microsoft Vendor
    2023-02-07T07:32:56.9933333+00:00

    Hi @Stefan Diedericks ,

    You can also use the following command to loop through the user's userprinciplename in the CSV.

     

    $UserList = Import-CSV C:\temp\users.csv
    
    ForEach ($User in $UserList) {
    
    Set-Mailbox -Identity $user. userprinciplename -MaxSendSize 25mb -MaxReceiveSize 35mb
    
    }
    

    You can create a CSV file by referring to the following:

    2023-2-7-1


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    0 comments No comments