import re


def rule(event):
    if all(
        [
            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(
                [
                    "Get-ChildItem " in event.deep_get("CommandLine", default=""),
                    "dir " in event.deep_get("CommandLine", default=""),
                    "gci " in event.deep_get("CommandLine", default=""),
                    "ls " in event.deep_get("CommandLine", default=""),
                ]
            ),
            any(
                [
                    "Get-Content " in event.deep_get("CommandLine", default=""),
                    "gc " in event.deep_get("CommandLine", default=""),
                    "cat " in event.deep_get("CommandLine", default=""),
                    "type " in event.deep_get("CommandLine", default=""),
                    "ReadAllBytes" in event.deep_get("CommandLine", default=""),
                ]
            ),
            any(
                [
                    all(
                        [
                            " ^| " in event.deep_get("CommandLine", default=""),
                            re.match(r"^.*\\.*.lnk.*$", event.deep_get("CommandLine", default="")),
                            "-Recurse" in event.deep_get("CommandLine", default=""),
                            "-Skip " in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                    all(
                        [
                            " -ExpandProperty " in event.deep_get("CommandLine", default=""),
                            re.match(r"^.*\\.*.lnk.*$", event.deep_get("CommandLine", default="")),
                            "WriteAllBytes" in event.deep_get("CommandLine", default=""),
                            " .length " in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
