r/PowerShell • • Mar 04 '26

Azure PowerShell Runbook: empty lines in output

Hi all, I have a script to read the current permissions on shared mailboxes. It is triggered by ServiceNow and returns the runbook output. When I run it in test pane it shows the information line by line - good so far.

When I run it regulary the output creates an additional empty line after each entry. Do you have any advice, how to get rid of those empty lines? Images are not allowed so I'm not able to show you.

I'm not a pro Powershell developer and my question is not about how I wrote the script - it is about the output difference.

Param(
    [Parameter(Mandatory=$True)]
    [string]$PrimarySmtp,

    [Parameter(Mandatory=$True)]
    [string]$RITM
)
Connect-ExchangeOnline -ManagedIdentity -Organization xxx.onmicrosoft.com |out-null

try {
    
    $exist = Get-Mailbox $PrimarySmtp -ErrorAction Stop |Out-Null

    $SendAs = @('','SendAs','-------------')
    $SendAs += (Get-RecipientPermission $PrimarySmtp |? {$_.trustee -notlike "*NT AUTH*"}).Trustee

    $SendOB = @('','SendOB','-------------')
    $SendOBTemp = (Get-Mailbox $PrimarySmtp).GrantSendOnBehalfTo
    $SendOBTemp | % { $SendOB += (Get-Mailbox $_).PrimarySmtpAddress }

    $FullAccess = @('','FullAccess','-------------')
    $FullAccess += (Get-MailboxPermission $PrimarySmtp |? {$_.user -notlike "*NT AUTH*"}).User

    $PrimarySmtp

    if($FullAccess[3] -eq $null) { 
        $FullAccess += 'no permissions set'
        $FullAccessmsg = [PSCustomObject]@{ "FullAccess" = $FullAccess }
    } else {
        $FullAccessmsg = [PSCustomObject]@{ "FullAccess" = $FullAccess }
    }
    
    if($SendOB[3] -eq $null) { 
        $SendOB += 'no permissions set'
        $SendOBmsg = [PSCustomObject]@{ "SendonBehalf" = $SendOB }
    } else {
        $SendOBmsg = [PSCustomObject]@{ "SendonBehalf" = $SendOB }
    }

    if($SendAs[3] -eq $null) { 
        $SendAs += 'no permissions set'
        $SendAsmsg = [PSCustomObject]@{ "SendAs" = $SendAs }
    } else {
        $SendAsmsg = [PSCustomObject]@{ "SendAs" = $SendAs }
    }
    
    $FullAccessmsg.FullAccess
    $SendOBmsg.SendonBehalf
    $SendAsmsg.SendAs
    
}
catch {
    $finalmsg = "Error: Mail address doesn't exist"
    $finalmsg
}

Disconnect-Exchangeonline -Confirm:$False |out-null
2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/AdeelAutomates Mar 04 '26

That's an output thing in automation account. We have it as well.