r/PowerShell • u/Ok_Decision773 • 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
View all comments
Show parent comment
1
u/Ok_Decision773 Mar 04 '26 edited Mar 04 '26
this is to get one empty line before each block of results. that s fine and it doesn't have the empty lines in local powershell or in azure test pane. there it's like:
but the regular runbook result is: