Hello!
I'm looking to make my job creating resource mailboxes easier.
Since all my meeting rooms will have the same settings, I've written a script to take care of them.
However, I can't seem to get the resource customs set for the room.
Here is my script:
cls
Import-Module ActiveDirectory
# Create an array of your meetingroom resources
$roomResource = @("Videokonferanse", "Laserutstyr", "Gjestekontor", "TV", "PC", "Projektor", "Flipover", "Wifi", "Whiteboard")
## Variables ##
$roomName = Read-Host "Enter room name"
$userPrincipal = $roomName + "@testlabb.ad"
$office = Read-Host "Office location(In full name, ex: Porsgrunn)"
$capacity = Read-Host "Enter room capacity"
$resources = Read-Host "Room resources:ex(Videokonferanse, Laserutstyr, Gjestekontor, TV, PC, Projektor, Flipover, Wifi, Whiteboard)"
$resourcesArray = $resources.Split(",")
$resourcesTrimmed = ForEach($verdi in $resourcesArray){$verdi.Trim()}
# Create funtion
Function createRoom
{
[cmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$roomName,
[Parameter(Mandatory=$True)]
[string]$office,
[Parameter(Mandatory=$True)]
[string]$capacity
)
# Settings for room mailbox
New-Mailbox -Name $roomName -Alias $roomName -OrganizationalUnit 'testlabb.ad/Exchange/Rom' -UserPrincipalName $userPrincipal -SamAccountName $roomName -FirstName $roomName -Initials '' -LastName '' -Room
Set-CalendarProcessing -Identity $roomName -AutomateProcessing AutoAccept -BookingWindowInDays 365 -AddOrganizerToSubject $false -DeleteSubject $false
Set-Mailbox -Identity $roomName -ResourceCapacity $capacity
$roomEquipment = ""
ForEach($room in $roomResource)
{
ForEach($arrayItem in $resourcesTrimmed)
{
if($arrayItem -eq $room)
{
If($roomEquipment)
{
$roomEquipment += ","
}
$roomEquipment += $room
}
}
}
$roomEquipmentArray = $roomEquipment.Split(",")
$ResourceMailbox = Get-Mailbox -Identity $roomName
ForEach($equipment in $roomEquipmentArray)
{
$ResourceMailbox.ResourceCustom.Add($equipment)
}
Set-Mailbox -ResourceCustom $ResourceMailbox.ResourceCustom.Add
#Set Office location
$user = Get-ADUser -Identity $roomName
Set-ADUser -Identity $user.SamAccountName -Office $office
}
# Run Function
createRoom -roomName $roomName -office $office -capacity $capacity
The part I'm having issues with is this:
$ResourceMailbox = Get-Mailbox -Identity $roomName
ForEach($equipment in $roomEquipmentArray)
{
$ResourceMailbox.ResourceCustom.Add($equipment)
}
Set-Mailbox -ResourceCustom $ResourceMailbox.ResourceCustom.Add
I'm getting this error message:
Cannot process argument transformation on parameter 'ResourceCustom'. Cannot convert value "System.Void Add(string item
)" to type "Microsoft.Exchange.Data.MultiValuedProperty`1[System.String]". Error: "Conversion from System.Management.Au
tomation.PSObject to System.String has not been implemented."
+ CategoryInfo : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox
Can anyone help me?