Solved

Using set commands in exchange

Posted on 2012-03-13
28
1,697 Views
Last Modified: 2012-03-20
Dear Team,

I need to use the set command for multiple queries with the same script. For example, please find the below the below script and which will run one set command for all the mailbox and  i saved as ps1 and have csv file as well.

__________________________

Import-Csv C:\Users\User.csv | % {
 New-Mailbox -identity $_.Name -Alias $_.Alias  -Database DB1 -Organizationalunit "users" -Room | Set-Mailbox -CustomAttribute4 $_.CA4 -CustomAttribute5 $_.CA5 -customAttribute6 $_.CA6

__________________________

Also, i need to involve another set command, for example set-Calendarprocessing for the mailboxes in the above script.
1) how to add multiple set commands with one script.
2) how can i refer the multiple csv files for each set commands.

Please suggest.
0
Comment
Question by:sekar_raj32
  • 12
  • 8
  • 8
28 Comments
 
LVL 12

Expert Comment

by:Navdeep
ID: 37718566
Hi,

Try the following script with few users first.

$ColItems = import-csv pathToCSVFile
foreach($colItem in $colItems)
  {
      $id = $ColItem.Name  # assuming you have a column called Name under which you have mailbox name
       $als=$colItem.Alias
        $ca4=$coltem.ca4
        $ca5=$coltem.ca5
         $ca6=$coltem.ca6

New-Mailbox -identity $id -Alias $als  -Database DB1 -Organizationalunit "users" -Room | Set-Mailbox -CustomAttribute4 $CA4 -CustomAttribute5 $CA5 -customAttribute6 $CA6

Set-calendarProcessing -identity $id  #and rest of your command with attributes
                                                          # save the value as done for ca4,ca5 etc
  }

Hope that helps

Regards,
Navdeep [v-2nas]
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37718573
try this

$Users = Import-Csv C:\Users\User.csv

Foreach ($User in $Users){
 New-Mailbox -identity $User.Name -Alias $User.Alias  -Database DB1 -Organizationalunit "users" -Room 
 
 # Active Directory Latency
 do{
 
 $Mailbox = Get-Mailbox -Identity $User.name -ErrorAction Silentlycontinue
 
 }while ($Mailbox -eq $null)
 
Set-Mailbox -CustomAttribute4 $User.CA4 -CustomAttribute5 $User.CA5 -customAttribute6 $User.CA6

another cmdle......

..........
}

Open in new window

0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37718874
Hi v-2nas,

I am able to run the script sucessfully, but need your help on applying some settings:

When i run the script it gave error

Set-calendarProcessing -identity $id -Scheduleonlyduringworkinghours $sch

and it says need to submit boolean like only true or false, 0 or 1

I understand that i am calling the column name as $sch..

So please let me know how to run with the columnname as Sch, because from this setting some of the user need to be true and false..

So how to add this into the script. Please suggest
0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37719471
Hi,

You can pass True or false value just like any other value.

Regards,
Navdeep [v-2nas]
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37723389
Let me say clearly..  kinldy find the below script

$ColItems = import-csv C:\Users\Testcr.csv
foreach($colitem in $colitems)
{
  $Name= $colItem.Name
  $als=$colItem.Alias
  $Office=$colitem.office
  $ca4=$colItem.ca4
  $ca5=$colItem.ca5
  $ca6=$colItem.ca6
  $ca8=$colItem.ca8
  $ca9=$colItem.ca9
  $ca10=$colItem.ca10
  $ca15=$colItem.ca15
  $send=$colitem.send
  $Receive=$colitem.Receive
  $Sendandreceive=$colitem.Sendandreceive
  $RL=$colitem.RL
  $ResCapacity=$colitem.ResCapacity
  $Rescustom=$colitem.Rescustom
  $ResDeg=$colitem.ResDeg
  $MaxDur=$colitem.MaxDur
  $Bookday=$colitem.Bookday
  $rec=$colitem.rec
  $BIP=$colitem.BIP
  $sch=$colitem.sch
 
New-Mailbox -Name $Name -Alias $Als -Database DB1 -Organizationalunit "users" -Room |
Set-Mailbox -CustomAttribute4 $CA4 -CustomAttribute5 $CA5 -customAttribute6 $CA6 -CustomAttribute8 $CA8 -CustomAttribute9 $CA9 -customAttribute10 $CA10 -customAttribute15 $CA15 -UseDatabaseQuotaDefaults $false -IssueWarningQuota $_.Send -ProhibitSendQuota $_.Receive -ProhibitSendReceiveQuota $_.SendandReceive -RecipientLimits $_.RL -ResourceCapacity $_.ResCapacity -ResourceCustom $_.Rescustom
Set-calendarProcessing -identity $name -ResourceDelegates $ResDeg -MaximumDurationInMinutes
$Maxdur -BookingWindowInDays "$Bookdays"
-AllowRecurringMeetings $rec
-AllBookInpolicy $BIP
ScheduleOnlyDuringWorkHours $sch

}

______________________________________________________

In the above script i am not able to run for the below three commands, because it is asking me to define true or false.. but i dont want to mention the true or false directly to the script. i want to define the column name and get the information from csv file and it should define true or false to the user conference mailbox. Because i have alot of mailbox and need to apply settings(True or false) to the conference mailboxes.
-AllowRecurringMeetings $rec
-AllBookInpolicy $BIP
ScheduleOnlyDuringWorkHours $sch

_______________________________________

Kindly suggest..
0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37723438
Ok, what is the value stored in $rec, $BIP, $sch, i assume either true or false based on your requirement.... is it correct ?

if answer is yes then try this , make changes to the script $BIP=$colitem.BIP.ToString() similarly for $rec, $sch and run the script for only 1 or 2 users.

Regards,
Navdeep [v-2nas]
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37723528
I changed in the srcipt but it still showing the error.. so i just checked only that schdule duration and modified the script as well. but still showing the error and its not converting.. please check the below

$ColItems = import-csv C:\Users\Testcr.csv
foreach($colitem in $colitems)
{
  $Name= $colItem.Name
  $schonly=$colitem.schonly.ToString()
 
Set-calendarProcessing -identity $Name -ScheduleOnlyDuringWorkHours $schonly
}


[PS] C:\Users>.\Testshell.ps1
Cannot process argument transformation on parameter 'ScheduleOnlyDuringWorkHours'. Cannot convert value "System.String"
 to type "System.Boolean", parameters of this type only accept booleans or numbers, use $true, $false, 1 or 0 instead.
    + CategoryInfo          : InvalidData: (:) [Set-CalendarProcessing], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-CalendarProcessing
0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37723624
after this command runs and fails, can you enter $schonly and hit return and see what do you get. I believe you need $true or $false instead of just true or false.
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37723656
Nope.. i already tried to apply $true and $false in sheet, but still says the same error.

Also i just entered only $schonly and it doesn't show anything.
0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37723754
so $schonly has nothing inside it that's why you are hitting the error, it requires some troubleshooting, check the results without using tostring()
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37729950
No luck.. still having the same error..
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37736047
Room Mailbox QuotaRoom Mailbox AttributesRoom MailboxHi,

I used this CSV and below code.

$Users = Import-Csv C:\PS\User.csv
Foreach ($User in $Users){

New-Mailbox -Name $User.name -Database 'Server\SG1\DB1' -Alias $User.alias -UserPrincipalName ($User.alias + '@domain.com') `
-Room

do{
 
 $Mailbox = Get-Mailbox -Identity $User.name -ErrorAction Silentlycontinue
 
 }while ($Mailbox -eq $null)

Set-Mailbox -Identity $User.name -CustomAttribute4 $User.CA4 -CustomAttribute5 $User.CA5 -CustomAttribute6 $User.CA6
Set-Mailbox -Identity $User.name -IssueWarningQuota $User.Send -ProhibitSendQuota $User.Receive -ProhibitSendReceiveQuota $User.SendAndReceive -UseDatabaseQuotaDefaults:$false

}

Open in new window


The Output is, please refer to screenshot.

For the rest on of code, could you provide your final CSV file.
User.csv
0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37736086
Hi,

can you upload your sample csv file with one record?

Regards,
Navdeep [v-2nas]
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37736191
PowerShell Resultcontinue to my comments. here is code for last 3 attributes that you do facing a problem. I'm using Exchange 2007 and I believe that it will work on Exchange 2010 also, just subtitude the "Set-MailboxCalendarSettings" with "Set-CalendarSettings":

$Users = Import-Csv C:\PS\User.csv
Foreach ($User in $Users){

New-Mailbox -Name $User.name -Database 'Mensa\SG1\DB1' -Alias $User.alias -UserPrincipalName ($User.alias + '@sapura.com') `
-Room

do{
 
 $Mailbox = Get-Mailbox -Identity $User.name -ErrorAction Silentlycontinue
 
 }while ($Mailbox -eq $null)

Set-Mailbox -Identity $User.name -CustomAttribute4 $User.CA4 -CustomAttribute5 $User.CA5 -CustomAttribute6 $User.CA6
Set-Mailbox -Identity $User.name -IssueWarningQuota $User.Send -ProhibitSendQuota $User.Receive -ProhibitSendReceiveQuota $User.SendAndReceive -UseDatabaseQuotaDefaults:$false

#Set Room Resources

#$Room = Get-Mailbox -Identity $User.name
#$Room.ResourceCustom+=("$User."

Set-MailboxCalendarSettings $User.name -ResourceDelegates $User.ResDeg `
-MaximumDurationInMinutes $User.Maxdur -AllowRecurringMeetings $true `
-AllBookInPolicy $true -ScheduleOnlyDuringWorkHours $true
}

Open in new window


http://technet.microsoft.com/en-us/library/aa996340(v=exchg.80).aspx
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 7

Author Comment

by:sekar_raj32
ID: 37736497
Hi suriyaehnop,

Please understand i am able to run the script already but i was not able to run the $true or $false from the excel sheet.

From your script you directly mentioned that $true(please find below) and all but i dont want to do that, because i have multiple users to set with different options. so i need to run the script by pulling the details from the excel sheet and need to set $true or $false and not applying $true in the script directly.

______________________

-AllowRecurringMeetings $true `
-AllBookInPolicy $true -ScheduleOnlyDuringWorkHours $true
0
 
LVL 18

Accepted Solution

by:
suriyaehnop earned 250 total points
ID: 37736738
sorry for misunderstanding, I had modified the code:

$Users = Import-Csv C:\PS\User.csv
Foreach ($User in $Users){

New-Mailbox -Name $User.name -Database 'Server1\SG1\DB1' -Alias $User.alias -UserPrincipalName ($User.alias + '@domain.com') `
-Room

do{
 
 $Mailbox = Get-Mailbox -Identity $User.name -ErrorAction Silentlycontinue
 
 }while ($Mailbox -eq $null)

Set-Mailbox -Identity $User.name -CustomAttribute4 $User.CA4 -CustomAttribute5 $User.CA5 -CustomAttribute6 $User.CA6
Set-Mailbox -Identity $User.name -IssueWarningQuota $User.Send -ProhibitSendQuota $User.Receive -ProhibitSendReceiveQuota $User.SendAndReceive -UseDatabaseQuotaDefaults:$false

#Set Room Resources

#$Room = Get-Mailbox -Identity $User.name
#$Room.ResourceCustom+=("$User."

#[System.Convert]::ToBoolean($User.ARM)
#[System.Convert]::ToBoolean($User.ABP)
#[System.Convert]::ToBoolean($User.Schedule)

Set-MailboxCalendarSettings $User.name -ResourceDelegates $User.ResDeg `
-MaximumDurationInMinutes $User.Maxdur -AllowRecurringMeetings ([System.Convert]::ToBoolean($User.ARM)) `
-AllBookInPolicy ([System.Convert]::ToBoolean($User.ABP)) -ScheduleOnlyDuringWorkHours ([System.Convert]::ToBoolean($User.Schedule))
}

Open in new window


http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/300b5602-b16a-4a10-96fd-3e2e6ba29ed6/

http://connect.microsoft.com/PowerShell/feedback/details/298020/all-string-values-convert-to-boolean-true
User.csv
0
 
LVL 12

Assisted Solution

by:Navdeep
Navdeep earned 250 total points
ID: 37737219
Sorry got late for the party..... I hope the solution Suriya has give works. But if it doesn't then you need to do this way.
Instead of using $true or $false use 1 or 0

Now -AllBookInPolicy accepts either $false or $true not True/False

-AllBookInPolicy ([System.Convert]::ToBoolean($User.ABP)) returns  True/False

****************

Make changes in the code to use 0 or 1

# convert the string to int 32 value
[int] $a = $colitem.abip

#now make changes to System.Convert::ToBoolean

-AllBookInPolicy ([System.Convert]::ToBoolean($a)

*****************

Regards,
Navdeep [v-2nas]
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37740778
Hi Suryanoop:

Thank you very much and able to run the script..  Can you please explain the below lines scripts and the functions... this is just to learn myselft. please explain.

do{
 
 $Mailbox = Get-Mailbox -Identity $User.name -ErrorAction Silentlycontinue
 
 }while ($Mailbox -eq $null)

______________________________________________

I really appreciate your and Navdeep help . Thank you.
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37740792
Hi,

do{
 
 $Mailbox = Get-Mailbox -Identity $User.name -ErrorAction Silentlycontinue
 
 }while ($Mailbox -eq $null)

Open in new window


This code is to prevent AD Latency. I had experianced that when 1 scripts can do multiple task such as creating bulk mailbox and update mailbox attribute such as "Company, Title and etc", if i don't put this code, I will get error similiar to this:

 
Object "xxxxxx" could not be found. Please make sure that it was spell
ed correctly or specify a different object.
At C:\Users\scpsupport\Documents\createnewmailbox.ps1:141 char:1
+  <<<< Set-Mailbox -Identity $User.alias -ForwardingAddress $User.contact
    + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundEx
   ception
    + FullyQualifiedErrorId : 842AEAA

http://unlockpowershell.wordpress.com/2010/01/08/powershell-dealing-with-active-directory-latency/
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37740863
Thank you for the Explanation...
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37741011
From this script i am not able to add multiple users in the calendar delegates.. do you have any idea to add multiple users into the calendar delegates

I mentioned in the delegates column as like below. if i specify one user and able to run it successfully but unable to run multiple users.

"User1,User2"


Kindly advice
0
 
LVL 12

Expert Comment

by:Navdeep
ID: 37741085
Try like this $mydelegates = 'user1', 'user2'
coz enclosing " " powershell treat it as 1 string value
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37741134
Nope... its not working
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37741188
If you want to add multiple delegates it will remove previous added. I'm suggesting to give the delegate to the "Group" instead of "User"

http://support.microsoft.com/kb/945643/en-us
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37741895
Sorry.. i cannot create 5 or 6 users for one group.. instead of that i need to add multlple users as delegates. I have many conference mailboxes and need to create and need to set different multiple  deligates to each conference rooms.
So it will be better if i mentioned in csv and run the script in one time
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37745534
Actually i quite tough to do in one scripts. Here is script that you can add multiple uses on resource delegates but it require manually key in the name:

$Delegates = Get-MailboxCalendarSettings -Identity Room01
$1 = $Delegates.ResourceDelegates
$1
$2 = "User1@contoso.com","User2@contoso.com"
$1+=$2
$1

Set-MailboxCalendarSettings -Identity Room01 -ResourceDelegates $1
#Set-MailboxCalendarSettings Room01 -ResourceDelegates $User
$Delegate = Get-MailboxCalendarSettings -Identity Room01
$Delegate 

Open in new window


As you can see, in the script you manually identified the Room mailbox name and also list of user.

You may try to use the script which I provided previously and delegate to the group.After that you added the user to be member of the group. If it is work and you ok with it, then we can modified the script so that it can:

1. Create a room mailbox
2. Amend the attributes such CustomAttribute4 and etc
3. Set the mailbox quota
4. Set MailboxCalendarSettings such AllowRecurringMeetings
5. Create a ResourceDeletage DL group
6. Set MailboxCalendarSettings to apply DelegateResource

Lastly, manually added the user to ResourceDelegate DL
0
 
LVL 7

Author Comment

by:sekar_raj32
ID: 37745749
ok fine... i can set as a group and add manually the users resource DL. Thank you very much for your effort and support..

Thank you
0
 
LVL 18

Expert Comment

by:suriyaehnop
ID: 37745796
please try this code:


Kindly try it all out
User.csv
Test.jpg
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now