0
votes

I got this little code in PowerShell for O365:

$dispname = Read-Host 'Displayname of room'
$alias = read-Host 'Alias of name (no spaces, no domain)'
$capacity = read-host 'Capacity of room'
$loc = read-host 'Location of room (site)'
$smtp = $alias + "@test.com"
$group = "cr." + $loc + "[email protected]"

New-Mailbox -Name $alias -DisplayName $dispname -Room -office $loc

Set-Mailbox $alias -ResourceCapacity $capacity
Set-CalendarProcessing $alias -ScheduleOnlyDuringWorkHours $false -AutomateProcessing AutoAccept -AllowRecurringMeetings $True -AllowConflicts $False -ConflictPercentageAllowed 30 -MaximumConflictInstances 10 -BookingWindowInDays 365 -MaximumDurationInMinutes 1440
Set-MailboxCalendarConfiguration -identity $alias -WorkingHoursTimeZone "W. Europe Standard Time" -WorkingHoursStartTime 07:00:00 -WorkingHoursEndTime 18:00:00
Set-MailboxFolderPermission -Identity ${smtp}:\Calendar -User Default -AccessRights Reviewer

echo "Lokation is $loc"
echo "SMTP is $smtp"
echo "Gruppe is $group"

Add-DistributionGroupMember –Identity "$group" –Member "$smtp"

and I'm desperate because only the last line is getting me an error and I have absolutely no clue why.

The error is:

A positional parameter cannot be found that accepts argument '[email protected]'. CategoryInfo : InvalidArgument: (:) [Add-DistributionGroupMember], ParameterBindingException FullyQualifiedErrorId : PositionalParameterNotFound,Add-DistributionGroupMember PSComputerName : outlook.office365.com

So the variable $smtp is correctly set as the email address of the new ressource as well as the variable $group for the group name but somehow it does not work properly for PowerShell.

The thing is, when I do all the steps manually, so paste it in line for line in PowerShellit works. I got the error only when I run it as a script.

1
the code you posted cannot run since it is all in quoted strings. PLEASE, fix that so the displayed code is what you are actually working with. - Lee_Dailey
sorry, i got an error that i had to mark the code, maybe it was too much - Olaf313
thank you for fixing it! [grin] i see that robdy found the problem & the fix. good to know that you got it working as needed. ///// the usual source of that sort of thing [em/en-dash instead of hyphen; typographic quote instead of straight quote] is copying from a web page. it's worth checking on everything that you copy & paste. - Lee_Dailey
another possible source of glitches is the use of quotes around the parameter values >>> –Identity "$group" –Member "$smtp" <<<. that forces the object into a string ... and you USUALLY want the object to be a full object, not a "stringified" version of the object. [grin] - Lee_Dailey

1 Answers

0
votes

The code you pasted contains a character which is not dash

Add-DistributionGroupMember –Identity "$group" –Member "$smtp"
                       here ^         and here ^

Its output from ASCII Value Tool:

Char    Dec Hex Oct
–       150 96  226

While it should be:

Char    Dec Hex Oct
-       45  2D  55

Apparently, while pasting it to PowerShell, it's getting converted to - but it doesn't happen when you run the script. Delete the affected line, write it once again and it should work fine.