Avatar of Kamalasekar Parthasarathy
Kamalasekar ParthasarathyFlag for India asked on

Using set commands in exchange

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.
PowershellExchangeEmail Servers

Avatar of undefined
Last Comment
suriyaehnop

8/22/2022 - Mon
Navdeep

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]
suriyaehnop

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

ASKER
Kamalasekar Parthasarathy

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Navdeep

Hi,

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

Regards,
Navdeep [v-2nas]
ASKER
Kamalasekar Parthasarathy

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..
Navdeep

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]
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Kamalasekar Parthasarathy

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
Navdeep

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.
ASKER
Kamalasekar Parthasarathy

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Navdeep

so $schonly has nothing inside it that's why you are hitting the error, it requires some troubleshooting, check the results without using tostring()
ASKER
Kamalasekar Parthasarathy

No luck.. still having the same error..
suriyaehnop

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Navdeep

Hi,

can you upload your sample csv file with one record?

Regards,
Navdeep [v-2nas]
suriyaehnop

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
ASKER
Kamalasekar Parthasarathy

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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
suriyaehnop

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Kamalasekar Parthasarathy

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.
suriyaehnop

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/
ASKER
Kamalasekar Parthasarathy

Thank you for the Explanation...
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Kamalasekar Parthasarathy

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
Navdeep

Try like this $mydelegates = 'user1', 'user2'
coz enclosing " " powershell treat it as 1 string value
ASKER
Kamalasekar Parthasarathy

Nope... its not working
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
suriyaehnop

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
ASKER
Kamalasekar Parthasarathy

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
suriyaehnop

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Kamalasekar Parthasarathy

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
suriyaehnop

please try this code:


Kindly try it all out
User.csv
Test.jpg