We help IT Professionals succeed at work.

Exchange 2007 - Setting Languages mailbox parameter using cmdlets

Good day,

I sat the whole of yesterday figuring out how to make Out of Office messages in Exchange 2007 appear in English.

Basically what I have done is using cmdlets in the Exchange Management Shell.

Set-Mailbox -Identity "Full Name" -Languages "en-GB"

Restart the Exchange information store service and it is working 100%.

I reported back to the customer that I have a solution and that I would require a list of affected users in vsv format.

I have just received the list and we have over 200 users on the list.

I do not feel like changing every singe user manually. Is it possible to use a script to pull the details out of a csv file?

Alternatively, can a script be done to change all users on the server to "en-GB"

I would prefer the first option.

Would it be possible for someone to give me an example of how this script would look?

I know it is asking a lot, but if the script could also be commented as I would really like to learn how the cmdlets scripting works. I do not just want get a script and copy and paste it.

This would truely be appreciated.

Thank you,

Comment
Watch Question

Chris DentPowerShell Developer
Top Expert 2010

Commented:

How is the file formatted? In this example I assume the mailbox name is stored in a field headed with Name in the CSV.


Import-CSV YourFile.csv | ForEach-Object { Set-Mailbox $_.Name -Languages "en-GB" }


$_ represents the current line in the CSV file, and .Name is used to access the column. If you want to test it, add -WhatIf to the Set-Mailbox command.

As you see there's not a lot to it, but if you have more questions please don't hesitate to ask.

Chirs

Author

Commented:
Hi Chris,

I have attached an example of the file received. We have received the Full Names as per AD Users.

Would I be correct in assuming the following would also work:

Import-CSV YourFile.csv | ForEach-Object { Set-Mailbox -Identity "$_.Name" -Languages "$_.Language" }

or this one?

Import-CSV YourFile.csv | ForEach-Object { Set-Mailbox -Identity $_.Name -Languages $_.Language }
(without the "")

Thanks
example.csv
Chris DentPowerShell Developer
Top Expert 2010

Commented:

The second will, the first won't.

We can look at how the first will behave compared to the second like this:

Import-Csv example.csv.txt | ForEach-Object {
  Write-Host "Quoted Values: "  "$_.Name" "$_.Language" -ForegroundColor Red
  Write-Host "Unquoted Values: " $_.Name $_.Language -ForegroundColor Green
  Write-Host "Sub-Expressions in a string: $($_.Name) $($_.Language)" -ForegroundColor Cyan
}

The last is there to demonstrate how the more complex values can be inside quotes, it's what would be needed if we were to continue with the first version.

You should see the first looks pretty messy which is why it won't work for us here and why I made it red :)

Chris

Author

Commented:
Hi Chris,

Thanks a lot.

I see what you mean.

Now, for example - user is Sandra Jones (Name = Sandra, Surname= Jones, username = sandra)

What I do when I run the Set-Mailbox command is this:

Set-Mailbox -Identity "Sandra Jones" -Languages "en-GB"

But if I use

Import-CSV YourFile.csv | ForEach-Object { Set-Mailbox -Identity $_.Name -Languages $_.Language }

wont it try to execute it as follows:

Set-Mailbox -Identity Sandra Jones -Languages en-GB ?

Dont you need the " " around the Identity and Language parameters?

Thanks.
PowerShell Developer
Top Expert 2010
Commented:

No :)

All the quotes do is help use define the boundaries of a value. If the boundaries are already defined (by virtue of it being read from a CSV file) the quotes are not necessary in the command.

For example, we can consider these:

Get-Mailbox Sandra Jones     # Trying to process the command as if there were two parameters
Get-Mailbox "Sandra Jones"   # Processing the command with one parameter
$Name = "Sandra Jones"
Get-Mailbox $Name              # Processing the command with one parameter

$Name is equivalent to the $_.Name we use above.

Because "Sandra Jones" is assigned to the variable, as a single value, Get-Mailbox (and in the case above, Set-Mailbox) will be quite happy with it.

You might still use quotes if you're combining values, for instance if the CSV was this:

FirstName,LastName,Language
Sandra,Jones,en-GB

We might use something like this:

Import-CSV example.csv | %{ Get-Mailbox "$($_.FirstName) $($_.LastName)" }

This time we have PowerShell build the two different values into one string, after that it can use the value with Get-Mailbox.

% is an alias, shorthand, for ForEach-Object.

Chris

Author

Commented:
Awesome !!!

Thanks for clearing that up...

I have a much better understanding of it all now...

Thanks for the answers and lessons.

Be sure to expect to see many more questions from me with regards to this :D

But this specific issue is 100% resloved and perfectly clear !!

Chat soon

Author

Commented:
Awesome, detailed answers

Understand 100%
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Glad I could help out :)

Chris