Suppressing Text after New-DistributionList

Iron Contributor

I have a script which I am creating a distribution list (New-DistributionList).  However, the format of the output gets screwed up when the following text appears:

 

New! Office 365 Groups are the next generation of  distribution lists.
Groups give teams shared tools for collaborating using email, files, a calendar, and more.
You can start right away using the New-UnifiedGroup cmdlet.

 

How do you suppress this text?  I tried to pipe it to out-null to no avail.

16 Replies

Could you post the script?

 

What you could do is to store the output in a variable, then output it with a small delay.

Function Loop([string]$Person)
{
    $People = @()
    while ($Person -ne "")
    {
        $temp=Get-msoluser -UserPrincipalName $Person -ErrorAction SilentlyContinue
        if ($temp) {$People+=$Person}
        else {Write-Host "Not a valid email address: $Person"}
        $Person = Read-Host " "
    }
    return $People
}
Function Create-VacationCalendar
{
    "Logging into Office 365"
    " "
    .\ConnectToOffice365.ps1
    " "

    $RoomMailbox = Read-Host "New vacation calendar name"
    $ApproversGroup = "SG-$RoomMailbox Approvers"
    $RegularGroup = "SG-$RoomMailbox"
    " "

    "Creating the two security groups for the calendar:  $ApproversGroup and $RegularGroup"
    " "

    "Enter the owners of the $ApproversGroup group (Press just the Enter key to finish)"
    $ApproverOwner = Read-Host " "
    $ApproverOwners = Loop $ApproverOwner
    " "

    Write-Host "Enter the internet address of the approvers for the calendar (Press just the Enter key to finish)"
    $Approver = Read-Host " "
    $Approvers = Loop $Approver
    " "

    "Enter the owners of the $RegularGroup group (Press just the Enter key to finish)"
    $UserOwner = Read-Host " "
    $UserOwners = Loop $UserOwner
    " "
    "Enter the people who will be accessing the calendar (Press just the Enter key to finish)"
    $User = Read-Host " "
    $Users = Loop $User
    " "

    Write-Host -NoNewline "Creating security group: $ApproversGroup..."
    New-DistributionGroup -Name $ApproversGroup -Type "Security" -ManagedBy $ApproverOwners -CopyOwnerToMember -Members $Approvers -PrimarySmtpAddress "$($ApproversGroup.Replace(' ','_'))@domain.com" | Out-Null
    Write-Host "Done."

    Write-host -NoNewline "Creating security group: SG-$RoomMailbox..."
    New-DistributionGroup -name "SG-$RoomMailbox" -Type "Security" -ManagedBy $UserOwners -CopyOwnerToMember -Members $Users -PrimarySmtpAddress "$($RegularGroup.Replace(' ','_'))@domain.com" | Out-Null
    Write-Host "Done."

    Write-Host -NoNewline "Creating Room Mailbox: $RoomMailbox..."
    New-Mailbox -name $RoomMailbox -Room -PrimarySmtpAddress "$($RoomMailbox.Replace(' ','_'))@harvardpilgrim.org"
    Write-Host "Done."

    Write-Host -NoNewline "Setting calendar options..."
    while (-not (Get-CalendarProcessing -Identity $RoomMailbox -ErrorAction SilentlyContinue)) {Write-host -NoNewline ".";Sleep 10}


    $AutomateProcessing = "AutoAccept"
    $AllowRecurringMeetings = $True
    $AllowConflicts = $True
    $MaximumDurationInMinutes = 0
    $ConflictPercentageAllowed = 100
    $MaximumConflictInstances = 10
    $BookingWindowInDays = 365
    $EnforceSchedulingHorizon = $False
    $AddOrganizerToSubject = $True
    $DeleteComments = $False
    $DeleteSubject = $False

    Set-CalendarProcessing -Identity $RoomMailbox `
        -AutomateProcessing $AutomateProcessing `
        -AllowRecurringMeetings $AllowRecurringMeetings `
        -AllowConflicts $AllowConflicts `
        -MaximumDurationInMinutes $MaximumDurationInMinutes `
        -ConflictPercentageAllowed $ConflictPercentageAllowed `
        -MaximumConflictInstances $MaximumConflictInstances `
        -BookingWindowInDays $BookingWindowInDays `
        -EnforceSchedulingHorizon $EnforceSchedulingHorizon `
        -AddOrganizerToSubject $AddOrganizerToSubject `
        -DeleteComments $DeleteComments `
        -DeleteSubject $DeleteSubject `
        -BookInPolicy $ApproversGroup `
        -ResourceDelegates $ApproversGroup | Out-Null
    Write-Host "Done."
}
Create-VacationCalendar

 Each time I run it, I try to format the output, but the info for using groups keeps messing the output up.

THe output looks like this:

PS>.\Create-VacationCalendar.ps1
Logging into Office 365

Importing Module:  MSOnline...........Done.
Importing Credentials To Variable.....Done.
Setting Variable For New-PSSession....Done.
Importing PSSession...................Done.
Connecting To MSOLService.............Done.

New vacation calendar name: Zeff Calendar

Creating the two security groups for the calendar:  SG-Zeff Calendar Approvers and SG-Zeff Calendar

Enter the owners of the SG-Zeff Calendar Approvers group (Press just the Enter key to finish)
 : zeff_wheelock@domain.com
 :

Enter the internet address of the approvers for the calendar (Press just the Enter key to finish)
 : zeff_wheelock@domain.com
 :

Enter the owners of the SG-Zeff Calendar group (Press just the Enter key to finish)
 : zeff_wheelock@domain.com
 :

Enter the people who will be accessing the calendar (Press just the Enter key to finish)
 : zwheeloc@domain.com
 :

Creating security group: SG-Zeff Calendar Approvers...New! Office 365 Groups are the next generation of distribution lis
ts.
Groups give teams shared tools for collaborating using email, files, a calendar, and more.
You can start right away using the New-UnifiedGroup cmdlet.
Done.
Creating security group: SG-Zeff Calendar...New! Office 365 Groups are the next generation of distribution lists.
Groups give teams shared tools for collaborating using email, files, a calendar, and more.
You can start right away using the New-UnifiedGroup cmdlet.
Done.
Creating Room Mailbox: Zeff Calendar...
Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Zeff Calendar             ZeffCalendar         bn6pr02mb2434    99 GB (106,300,440,576 bytes)
Done.
Setting calendar options....Done.

it should look like this:

PS>.\Create-VacationCalendar.ps1
Logging into Office 365

Importing Module:  MSOnline...........Done.
Importing Credentials To Variable.....Done.
Setting Variable For New-PSSession....Done.
Importing PSSession...................Done.
Connecting To MSOLService.............Done.

New vacation calendar name: Zeff Calendar

Creating the two security groups for the calendar:  SG-Zeff Calendar Approvers and SG-Zeff Calendar

Enter the owners of the SG-Zeff Calendar Approvers group (Press just the Enter key to finish)
 : zeff_wheelock@domain.com
 :

Enter the internet address of the approvers for the calendar (Press just the Enter key to finish)
 : zeff_wheelock@domain.com
: Enter the owners of the SG-Zeff Calendar group (Press just the Enter key to finish) : zeff_wheelock@domain.com : Enter the people who will be accessing the calendar (Press just the Enter key to finish) : zwheeloc@domain.com : Creating security group: SG-Zeff Calendar Approvers...Done. Creating security group: SG-Zeff Calendar...Done. Creating Room Mailbox: Zeff Calendar...Done. Setting calendar options....Done.

For the Creating Room Mailbox line, I just put an Out-Null to suppress the result, so the result above should be the expected outcome if it ran successfully.

Couldnt you do something like this?
Store it to a variable, then give the output depending if its $null or not.

$newDB = New-DistributionGroup -Name $ApproversGroup -Type "Security" -ManagedBy $ApproverOwners -CopyOwnerToMember -Members $Approvers -PrimarySmtpAddress "$($ApproversGroup.Replace(' ','_'))@domain.com" 

If($newDB -ne $null) {

    "Completed successfully"
}
Else{"Error"}
Saving it to a variable won't work either. It still prints the Office 365 group message. I called Microsoft and they acknowledged the message and stated it is there only temporary but they have no timetable when they will remove it. Sometimes, Microsoft just does not think things through...

You create an array and the results to it, similar to below:

 

$DlArray = @()
$DlArray += "UserPrincipalName" + "," + "Comment"
$DlArray += "Creating security group:" + $_.ApproversGroup
$DlArray += "Creating security group: SG-" + $_.RoomMailbox

 

This will refine the results, you can add some logic to catch the errors.

I experience the same issue and I agree.  We should not have to put some crap code to deal with the message.  Microsoft should just not present that message or allow us to turn it off via the cmdlet.

 

Common MS think things through would you?

It is not an error though. It order to create a distribution list, you need to use New-DistributionList. As soon as you run it to create the list, then you have that unwanted text and there is no suppressing it. Oh well.
Any update on taking out the unwanted text?

I don't have the Cmdlet in front of me but that output could be minor warning message from the Cmdlet.  

Trying adding in -warningaction 'silentlycontinue' *or* -informationaction silentlycontinue to see if that suppresses the message.

 

Silly question... what Colour is the message? (that can help identify the type of message)

RED = Error, YELLOW = Warning

 

If it's neither then it might just be information in which case ideally -informatinaction silentlycontinue should let you go on without being pestered.

 

Sean

Good friend of Dr. Scripto

White. So it is not a warning or an error. It is a forced statement that cannot be blocked by sending it to Null.

 

PS> New-DistributionGroup -name "TEST DELETE" -type "Security" -CopyOwnerToMember -ManagedBy "my_email_address@domain.com" -PrimarySmtpAddress test_delete@domain.com| out-null
New! Office 365 Groups are the next generation of distribution lists.
Groups give teams shared tools for collaborating using email, files, a calendar, and more.
You can start right away using the New-UnifiedGroup cmdlet.

[ADMIN] [Connected] [Unrestricted] 08/20/2018 09:37:29 O:\Office365
PS>

 

It still displays the feature. Messes up my formatting on the page.

It appears to be "Information" which normally could be re-directed using "InformationAction" however that parameter has not been exposed in the New-DistributionGroup Cmdlet for Exchange Online.

 

I've created an entry in UserVoice for the Exchange Online Administration.   

https://office365.uservoice.com/forums/273493-office-365-admin/suggestions/35163415-new-distribution...

 

But you are correct, at this time the content cannot be captured or redirected.

 

Thanks.  Already put my 3 votes in...  <smile>

Apparently I am not allowed to like this but I whole heartedly agree!
Apparently I am not allowed to like this either but I whole heartedly agree!
hi, any update?? its 2 years passed since the last reply..I'm now have the issue and don't know how to hide this info banner..
thanks