def rule(event):
    if all(
        [
            any(
                [
                    any(
                        [
                            event.deep_get("Image", default="").endswith("\\powershell.exe"),
                            event.deep_get("Image", default="").endswith("\\pwsh.exe"),
                        ]
                    ),
                    event.deep_get("OriginalFileName", default="")
                    in ["PowerShell.EXE", "pwsh.dll"],
                ]
            ),
            "Add-PSSnapin" in event.deep_get("CommandLine", default=""),
            any(
                [
                    "Microsoft.Exchange.Powershell.Snapin"
                    in event.deep_get("CommandLine", default=""),
                    "Microsoft.Exchange.Management.PowerShell.SnapIn"
                    in event.deep_get("CommandLine", default=""),
                ]
            ),
            not all(
                [
                    event.deep_get("ParentImage", default="")
                    == "C:\\Windows\\System32\\msiexec.exe",
                    "$exserver=Get-ExchangeServer ([Environment]::MachineName) -ErrorVariable exerr 2> $null"
                    in event.deep_get("CommandLine", default=""),
                ]
            ),
        ]
    ):
        return True
    return False
