Piping a csv to the Set-Mailbox cmdlet

Hi,

I have a CSV file populated with a list of users SPN's in the following format:

User

user1@domain.local

user2@domain.local

I am getting an odd error when I run the following:

$users = c:\scripts\userlist.csv

foreach ($user in $users) {Set-Mailbox $user -UseDatabaseQuotaDefaults $false -ProhibitSendReceiveQuota
1 -IssueWarningQuota 1 -ProhibitSendQuota 1 -hiddenfromaddresslistsenabled $true}

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "@{User=user1@domain.local}" value of type "Deserialized.System.Management.Automation.PSCustomObject" to type "Microsoft.Exchange.Configuration.Tasks.MailboxId
Parameter".



When I do a foreach ($user in $users) {write-host $user} I get the contents of the CSV but with "@{user=" prepended to every entry.

What am I doing wrong? Any help much appreciated.

September 4th, 2014 9:48am

Hi,

You'll need to specify the User property:

$users = c:\scripts\userlist.csv

foreach ($user in $users) {

    Set-Mailbox $user.User -UseDatabaseQuotaDefaults $false -ProhibitSendReceiveQuota 1 -IssueWarningQuota 1 -ProhibitSendQuota 1 -hiddenfromaddresslistsenabled $true
    
}
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2014 9:54am

Yes my heading name in the CSV is user.

Thanks for this Mike, this was driving me demented.

September 4th, 2014 10:02am

Cheers, you're welcome.
Free Windows Admin Tool Kit Click here and download it now
September 4th, 2014 10:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics