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("TargetFilename", default="").endswith(".ps1"),
            not any(
                [
                    "__PSScriptPolicyTest_" in event.deep_get("TargetFilename", default=""),
                    all(
                        [
                            event.deep_get("TargetFilename", default="").startswith("C:\\Users\\"),
                            "\\AppData\\Local\\Temp\\"
                            in event.deep_get("TargetFilename", default=""),
                        ]
                    ),
                    event.deep_get("TargetFilename", default="").startswith("C:\\Windows\\Temp\\"),
                ]
            ),
        ]
    ):
        return True
    return False
