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"],
                ]
            ),
            not any(
                [
                    any(
                        [
                            event.deep_get("ParentImage", default="").endswith(
                                ":\\Windows\\explorer.exe"
                            ),
                            event.deep_get("ParentImage", default="").endswith(
                                ":\\Windows\\System32\\CompatTelRunner.exe"
                            ),
                            event.deep_get("ParentImage", default="").endswith(
                                ":\\Windows\\SysWOW64\\explorer.exe"
                            ),
                        ]
                    ),
                    event.deep_get("ParentImage", default="")
                    == ":\\$WINDOWS.~BT\\Sources\\SetupHost.exe",
                ]
            ),
            not any(
                [
                    all(
                        [
                            event.deep_get("ParentImage", default="").endswith(
                                "\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
                            ),
                            " --ms-enable-electron-run-as-node "
                            in event.deep_get("ParentCommandLine", default=""),
                        ]
                    ),
                    all(
                        [
                            ":\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_"
                            in event.deep_get("ParentImage", default=""),
                            event.deep_get("ParentImage", default="").endswith(
                                "\\WindowsTerminal.exe"
                            ),
                        ]
                    ),
                    event.deep_get("ParentImage", default="").endswith(
                        ":\\Program Files\\Windows Defender Advanced Threat Protection\\SenseIR.exe"
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
