You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Intune推送命令卸载Python 3.12.3失败求助

解决Intune推送Python 3.12.3卸载命令无响应的问题

核心问题排查与修复

  1. 修正命令拼写错误
    你提供的PowerShell命令中%usernaame%多了一个字母a,正确写法应为%USERNAME%,拼写错误会直接导致路径无效,命令无法执行。

  2. 替换用户路径变量为Intune兼容写法
    Intune默认以系统上下文运行命令,%USERNAME%这类用户环境变量无法被正确解析。推荐用PowerShell自动定位当前登录用户的卸载程序路径:

    $userProfile = Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.LocalPath -like "C:\Users\*" -and $_.Loaded -eq $true } | Select-Object -ExpandProperty LocalPath
    $uninstallerPath = Join-Path -Path $userProfile -ChildPath "AppData\Local\Package Cache\{5ee4d2b6-a5dc-4321-b6bd-3ebc98120a51}\python-3.12.3-amd64.exe"
    if (Test-Path $uninstallerPath) {
        Start-Process -FilePath $uninstallerPath -ArgumentList "/uninstall /quiet" -Wait -NoNewWindow
    }
    

    该脚本会自动匹配当前加载的用户配置文件,避免硬编码路径带来的变量解析问题。

  3. 调整Intune执行上下文权限
    Python用户级安装程序需要用户上下文权限才能访问AppData目录。在Intune创建脚本部署时,务必勾选以登录用户身份运行选项,否则系统账户无法读取用户私有目录内容。

  4. 改用注册表获取卸载命令的标准方式
    硬编码缓存路径容易因版本或安装差异失效,可通过注册表直接调用系统注册的卸载字符串:

    $uninstallString = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object { $_.DisplayName -like "*Python 3.12.3*" } | Select-Object -ExpandProperty UninstallString
    if ($uninstallString) {
        Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString /quiet" -Wait -NoNewWindow
    }
    

    这种方式兼容性更强,无需依赖固定的缓存路径。

验证步骤

  • 先在目标设备上以用户身份运行上述PowerShell脚本,确认能正常卸载Python
  • 在Intune中创建PowerShell脚本部署任务,勾选以登录用户身份运行和隐藏脚本窗口
  • 部署后查看Intune设备状态报告,确认脚本执行成功

内容的提问来源于stack exchange,提问作者area845

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 07:34:54