def rule(event):
    if all(
        [
            "__PSScriptPolicyTest_" in event.deep_get("TargetFilename", default=""),
            not any(
                [
                    event.deep_get("Image", default="")
                    in [
                        "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
                        "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
                        "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell_ise.exe",
                        "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
                        "C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell_ise.exe",
                        "C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe",
                    ],
                    all(
                        [
                            any(
                                [
                                    "C:\\Program Files\\WindowsApps\\Microsoft.PowerShellPreview"
                                    in event.deep_get("Image", default=""),
                                    "\\AppData\\Local\\Microsoft\\WindowsApps\\Microsoft.PowerShellPreview"
                                    in event.deep_get("Image", default=""),
                                ]
                            ),
                            event.deep_get("Image", default="").endswith("\\pwsh.exe"),
                        ]
                    ),
                    event.deep_get("Image", default="")
                    in [
                        "C:\\Windows\\System32\\dsac.exe",
                        "C:\\Windows\\System32\\sdiagnhost.exe",
                        "C:\\Windows\\System32\\ServerManager.exe",
                        "C:\\Windows\\System32\\wsmprovhost.exe",
                        "C:\\Windows\\SysWOW64\\sdiagnhost.exe",
                    ],
                ]
            ),
        ]
    ):
        return True
    return False
