import re


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"],
                ]
            ),
            any(
                [
                    re.match(r"^.*join.*split.*$", event.deep_get("CommandLine", default="")),
                    "( $ShellId[1]+$ShellId[13]+'x')" in event.deep_get("CommandLine", default=""),
                    re.match(
                        r"^.*( $PSHome[.*]+$PSHOME[.*]+.*$",
                        event.deep_get("CommandLine", default=""),
                    ),
                    "( $env:Public[13]+$env:Public[5]+'x')"
                    in event.deep_get("CommandLine", default=""),
                    re.match(
                        r"^.*( $env:ComSpec[4,.*,25]-Join'').*$",
                        event.deep_get("CommandLine", default=""),
                    ),
                    "[1,3]+'x'-Join'')" in event.deep_get("CommandLine", default=""),
                ]
            ),
        ]
    ):
        return True
    return False
