New-AuditLogReport: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input

Evandro Boa Semedo 391 Reputation points
2021-11-04T19:38:12.047+00:00

Hi guys,

I've always run the script below since exchange server 2013 and after applying the exchange server 2019 CU11 and exchange server 2016 CU22 updates I've been getting the error below. I tried in various ways to get around and was not successful in getting around this situation. Can someone help me please?

146664-image.png

param(
[Parameter(Position=0, Mandatory=$true)]
$To,
[Parameter(Position=1, Mandatory=$true)]
$From,
[Parameter(Position=2, Mandatory=$true)]
$SmtpServer
)

function New-AuditLogReport {
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Microsoft.Exchange.Management.SystemConfigurationTasks.AdminAuditLogEvent]
$AuditLogEntry
)
begin {
$css = @'
<style type="text/css">
body { font-family: Tahoma, Geneva, Verdana, sans-serif;}
table {border-collapse: separate; background-color: #F2F2F2; border: 3px solid #103E69; caption-side: bottom;}
td { border:1px solid #103E69; margin: 3px; padding: 3px; vertical-align: top; background: #F2F2F2; color: #000;font-size: 12px;}
thead th {background: #903; color:#fefdcf; text-align: left; font-weight: bold; padding: 3px;border: 1px solid #990033;}
th {border:1px solid #CC9933; padding: 3px;}
tbody th:hover {background-color: #fefdcf;}
th a:link, th a:visited {color:#903; font-weight: normal; text-decoration: none; border-bottom:1px dotted #c93;}
caption {background: #903; color:#fcee9e; padding: 4px 0; text-align: center; width: 40%; font-weight: bold;}
tbody td a:link {color: #903;}
tbody td a:visited {color:#633;}
tbody td a:hover {color:#000; text-decoration: none;
}
</style>
'@
$sb = New-Object System.Text.StringBuilder
[void]$sb.AppendLine($css)
[void]$sb.AppendLine("<table cellspacing='0'>")
[void]$sb.AppendLine("<tr><td colspan='6'><strong>Exchange 2019 Administrator Audit Log Report for $((get-date).ToShortDateString())</strong></td></tr>")
[void]$sb.AppendLine("<tr>")
[void]$sb.AppendLine("<td><strong>Caller</strong></td>")
[void]$sb.AppendLine("<td><strong>Run Date</strong></td>")
[void]$sb.AppendLine("<td><strong>Succeeded</strong></td>")
[void]$sb.AppendLine("<td><strong>Cmdlet</strong></td>")
[void]$sb.AppendLine("<td><strong>Parameters</strong></td>")
[void]$sb.AppendLine("<td><strong>Object Modified</strong></td>")
[void]$sb.AppendLine("</tr>")
}

process {
[void]$sb.AppendLine("<tr>")
[void]$sb.AppendLine("<td>$($AuditLogEntry.Caller.split("/")[-1])</td>")
[void]$sb.AppendLine("<td>$($AuditLogEntry.RunDate.ToString())</td>")
[void]$sb.AppendLine("<td>$($AuditLogEntry.Succeeded)</td>")
[void]$sb.AppendLine("<td>$($AuditLogEntry.cmdletname)</td>")
$cmdletparameters += $AuditLogEntry.cmdletparameters | %{
"$($.name) : $($.value)<br>"
}
[void]$sb.AppendLine("<td>$cmdletparameters</td>")
[void]$sb.AppendLine("<td>$($AuditLogEntry.ObjectModified)</td>")
[void]$sb.AppendLine("</tr>")
$cmdletparameters = $null
}

end {
[void]$sb.AppendLine("</table>")
Write-Output $sb.ToString()
}
}

Send-MailMessage -To $To \-From $From
-Subject "Exchange Audit Log Report for $((get-date).ToShortDateString())" \-Body (Search-AdminAuditLog -StartDate ((Get-Date).AddHours(-24)) -EndDate (Get-Date) | New-AuditLogReport)
-SmtpServer $SmtpServer `
-BodyAsHtml

Source: https://github.com/Mjolinir/Powershell-Scripts/blob/master/Exchange/Auditreport.ps1

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
570 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,808 questions
{count} vote

Accepted answer
  1. Kubilay Ekici 81 Reputation points
    2022-07-04T08:15:28.29+00:00

    Yes seems there was a change in the code might be effect people using Exchange Server.
    I've worked on a similar case and did an alternate approach.


    #script starts here..  
      
    param(  
    [Parameter(Position=0, Mandatory=$true)]  
    $To,  
    [Parameter(Position=1, Mandatory=$true)]  
    $From,  
    [Parameter(Position=2, Mandatory=$true)]  
    $SmtpServer,  
    [Parameter(Position=3, Mandatory=$false)]  
    $Port="25"  
    )  
      
    function New-AuditLogReport {  
        [CmdletBinding()]  
        param(  
            [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]  
            $AuditReport  
            )  
    begin {  
    $css = @'  
    <style type="text/css">  
    body { font-family: Tahoma, Geneva, Verdana, sans-serif;}  
    table {border-collapse: separate; background-color: #F2F2F2; border: 3px solid #103E69; caption-side: bottom;}  
    td { border:1px solid #103E69; margin: 3px; padding: 3px; vertical-align: top; background: #F2F2F2; color: #000;font-size: 12px;}  
    thead th {background: #903; color:#fefdcf; text-align: left; font-weight: bold; padding: 3px;border: 1px solid #990033;}  
    th {border:1px solid #CC9933; padding: 3px;}  
    tbody th:hover {background-color: #fefdcf;}  
    th a:link, th a:visited {color:#903; font-weight: normal; text-decoration: none; border-bottom:1px dotted #c93;}  
    caption {background: #903; color:#fcee9e; padding: 4px 0; text-align: center; width: 40%; font-weight: bold;}  
    tbody td a:link {color: #903;}  
    tbody td a:visited {color:#633;}  
    tbody td a:hover {color:#000; text-decoration: none;  
    }  
    </style>  
    '@  
    $sb = New-Object System.Text.StringBuilder  
    [void]$sb.AppendLine($css)  
    [void]$sb.AppendLine("<table cellspacing='0'>")  
    [void]$sb.AppendLine("<tr><td colspan='6'><strong>Exchange Server Administrator Audit Log Report for $((get-date).ToShortDateString())</strong></td></tr>")  
    [void]$sb.AppendLine("<tr>")  
    [void]$sb.AppendLine("<td><strong>Caller</strong></td>")  
    [void]$sb.AppendLine("<td><strong>Run Date</strong></td>")  
    [void]$sb.AppendLine("<td><strong>Succeeded</strong></td>")  
    [void]$sb.AppendLine("<td><strong>Cmdlet</strong></td>")  
    [void]$sb.AppendLine("<td><strong>Parameters</strong></td>")  
    [void]$sb.AppendLine("<td><strong>Object Modified</strong></td>")  
    [void]$sb.AppendLine("</tr>")  
    }  
      
    process {  
    [void]$sb.AppendLine("<tr>")  
    [void]$sb.AppendLine("<td>$($AuditReport.Caller.split("/")[-1])</td>")  
    [void]$sb.AppendLine("<td>$($AuditReport.RunDate.ToString())</td>")  
    [void]$sb.AppendLine("<td>$($AuditReport.Succeeded)</td>")  
    [void]$sb.AppendLine("<td>$($AuditReport.cmdletname)</td>")  
    $cmdletparameters += $AuditReport.cmdletparameters | %{  
    "$($_.name) : $($_.value)<br>"  
    }  
    [void]$sb.AppendLine("<td>$cmdletparameters</td>")  
    [void]$sb.AppendLine("<td>$($AuditReport.ObjectModified)</td>")  
    [void]$sb.AppendLine("</tr>")  
    $cmdletparameters = $null  
    }  
      
    end {  
    [void]$sb.AppendLine("</table>")  
    Write-Output $sb.ToString()  
    }  
    }  
    # we are populating search entries on a specific object  
      
    $AuditLogEntries = Search-AdminAuditLog -StartDate ((Get-Date).AddHours(-24)) -EndDate (Get-Date)  
    # creating a customer object  
    $AuditReport = @()  
    foreach ($AuditLogEntry in $AuditLogEntries)  
    {  
    $rObj = New-Object PSObject  
    $rObj | Add-Member NoteProperty -Name "Caller" -Value $AuditLogEntry.Caller  
    $rObj | Add-Member NoteProperty -Name "RunDate" -Value $AuditLogEntry.RunDate  
    $rObj | Add-Member NoteProperty -Name "Succeeded" -Value $AuditLogEntry.Succeeded  
    $rObj | Add-Member NoteProperty -Name "CmdletName" -Value $AuditLogEntry.CmdletName  
    $rObj | Add-Member NoteProperty -Name "CmdletParameters" -Value $AuditLogEntry.CmdletParameters  
    $rObj | Add-Member NoteProperty -Name "ObjectModified" -Value $AuditLogEntry.ObjectModified  
    $AuditReport += $rObj  
    }  
      
    # Now we will create the report and sent by using $AuditReport object  
      
    Send-MailMessage -To $To `  
    -From $From `  
    -Subject "Exchange Audit Log Report for $((get-date).ToShortDateString())" `  
    -Body ($AuditReport | New-AuditLogReport) `  
    -SmtpServer $SmtpServer `  
    -Port $Port `  
    -BodyAsHtml  
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Evandro Boa Semedo 391 Reputation points
    2021-11-08T13:34:39.593+00:00

    This server the "TypeName" is correct and the script is working fine.

    Search-AdminAuditLog -ResultSize 250000 -StartDate ((Get-Date).AddHours(-1)) -EndDate (Get-Date) |
    Get-Member | ForEach-Object TypeName | Select-Object -Unique

    Microsoft.Exchange.Management.SystemConfigurationTasks.AdminAuditLogEvent

    147298-image.png

    Another Exchange server is different: <Deserialized.*>

    Search-AdminAuditLog -ResultSize 250000 -StartDate ((Get-Date).AddHours(-1)) -EndDate (Get-Date) |
    Get-Member | ForEach-Object TypeName | Select-Object -Unique

    Deserialized.Microsoft.Exchange.Management.SystemConfigurationTasks.AdminAuditLogEvent

    147400-image.png

    How can I serialize again this AdminAuditLogEvent class Powershell?

    https://learn.microsoft.com/en-us/previous-versions/exchange-server/exchange-150/ff330129(v=exchg.150)?redirectedfrom=MSDN


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.