def rule(event):
    if all(
        [
            any(
                [
                    event.deep_get("Image", default="").endswith("\\powershell.exe"),
                    event.deep_get("Image", default="").endswith("\\pwsh.exe"),
                ]
            ),
            any(
                [
                    "\\Windows\\Temp" in event.deep_get("CommandLine", default=""),
                    "\\Temporary Internet" in event.deep_get("CommandLine", default=""),
                    "\\AppData\\Local\\Temp" in event.deep_get("CommandLine", default=""),
                    "\\AppData\\Roaming\\Temp" in event.deep_get("CommandLine", default=""),
                    "%TEMP%" in event.deep_get("CommandLine", default=""),
                    "%TMP%" in event.deep_get("CommandLine", default=""),
                    "%LocalAppData%\\Temp" in event.deep_get("CommandLine", default=""),
                ]
            ),
            not any(
                [
                    "-WindowStyle hidden -Verb runAs" in event.deep_get("CommandLine", default=""),
                    "\\Windows\\system32\\config\\systemprofile\\AppData\\Local\\Temp\\Amazon\\EC2-Windows\\"
                    in event.deep_get("CommandLine", default=""),
                    any(
                        [
                            " >" in event.deep_get("CommandLine", default=""),
                            "Out-File" in event.deep_get("CommandLine", default=""),
                            "ConvertTo-Json" in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                    all(
                        [
                            event.deep_get("ParentImage", default="")
                            in [
                                "C:\\Windows\\System32\\Msiexec.exe",
                                "C:\\Windows\\SysWOW64\\Msiexec.exe",
                            ],
                            event.deep_get("Image", default="").endswith("\\powershell.exe"),
                            "-NoProfile -ExecutionPolicy Bypass -Command"
                            in event.deep_get("CommandLine", default=""),
                            "AppData\\Local\\Temp\\" in event.deep_get("CommandLine", default=""),
                            "Install-Chocolatey.ps1" in event.deep_get("CommandLine", default=""),
                        ]
                    ),
                ]
            ),
        ]
    ):
        return True
    return False
