import re


def rule(event):
    if all(
        [
            any(
                [
                    re.match(
                        r"\\w+`(\\w+|-|.)`[\\w+|\\s]", event.deep_get("ScriptBlockText", default="")
                    ),
                    re.match(
                        r"\"(\\{\\d\\}){2,}\"\\s*-f", event.deep_get("ScriptBlockText", default="")
                    ),
                    re.match(
                        r"(?i)\\$\\{`?e`?n`?v`?:`?p`?a`?t`?h`?\\}",
                        event.deep_get("ScriptBlockText", default=""),
                    ),
                ]
            ),
            not any(
                [
                    "${env:path}" in event.deep_get("ScriptBlockText", default=""),
                    any(
                        [
                            "it will return true or false instead"
                            in event.deep_get("ScriptBlockText", default=""),
                            "The function also prevents `Get-ItemProperty` from failing"
                            in event.deep_get("ScriptBlockText", default=""),
                        ]
                    ),
                    all(
                        [
                            event.deep_get("Path", default="").startswith(
                                "C:\\Program Files\\Microsoft\\Exchange Server\\"
                            ),
                            event.deep_get("Path", default="").endswith(
                                "\\bin\\servicecontrol.ps1"
                            ),
                            "`r`n" in event.deep_get("ScriptBlockText", default=""),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
