You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过CMD或PowerShell远程批量卸载Windows 10设备上的SourceTree

如何通过CMD或PowerShell远程批量卸载Windows 10设备上的SourceTree

我来帮你搞定这个批量卸载的问题!针对Windows 10上的SourceTree远程批量卸载,这里有几个靠谱的方案,不用手动删文件清注册表那么麻烦:

方案一:PowerShell原生包管理(最便捷)

PowerShell的Get-PackageUninstall-Package能直接识别大部分已安装软件,操作起来特别省心:

  1. 先在单台机器上测试本地卸载(确保命令有效):
Get-Package -Name "*SourceTree*" | Uninstall-Package -Force

-Force参数是用来跳过确认提示,适合批量操作。

  1. 远程批量执行:
    先把要操作的机器列表存起来,然后用Invoke-Command批量推送命令:
# 替换成你的目标机器名/IP列表
$targetComputers = @("PC-001", "PC-002", "192.168.1.101")
# 远程执行卸载,需要管理员权限
Invoke-Command -ComputerName $targetComputers -ScriptBlock {
    Get-Package -Name "*SourceTree*" | Uninstall-Package -Force
}

方案二:用WMI 同时支持CMD和PowerShell

如果你的环境里有些机器用CMD更顺手,或者PowerShell的包管理没识别到SourceTree,WMI的Win32_Product类也能搞定:

CMD单台远程卸载

wmic /node:PC-001 product where "name like '%SourceTree%'" call uninstall /nointeractive

/nointeractive是静默卸载,不会弹出窗口。

PowerShell批量远程卸载

$targetComputers = @("PC-001", "PC-002")
Get-WmiObject -ComputerName $targetComputers -Class Win32_Product -Filter "Name like '%SourceTree%'" | ForEach-Object {
    $uninstallResult = $_.Uninstall()
    # 可以加个结果判断,比如输出卸载状态
    Write-Host "卸载$($_.PSComputerName)上的SourceTree:$($uninstallResult.ReturnValue)"
}

小提醒:Win32_Product类偶尔会触发MSI的自检修复,但卸载操作是安全的,不用太担心。

方案三:从注册表获取卸载字符串执行(兜底方案)

如果上面两种方法都没识别到SourceTree,大概率是软件没注册到系统的包管理里,这时候可以从注册表找它的卸载命令:

  1. 先远程查询目标机器上SourceTree的卸载信息:
Invoke-Command -ComputerName $targetComputers -ScriptBlock {
    # 查32位和64位注册表路径
    $uninstallPaths = @(
        "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
        "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
    )
    Get-ItemProperty $uninstallPaths | Where-Object {
        $_.DisplayName -like "*SourceTree*" -and $_.UninstallString
    } | Select-Object DisplayName, UninstallString, PSComputerName
}
  1. 拿到卸载字符串后,比如结果是"C:\Program Files\SourceTree\uninst.exe" /silent或者msiexec /x {12345678-ABCD-EFGH-IJKL-1234567890AB} /qn,直接远程执行这个命令就行:
Invoke-Command -ComputerName PC-001 -ScriptBlock {
    # 替换成你查到的卸载字符串
    & "C:\Program Files\SourceTree\uninst.exe" /silent
}

前置注意事项

  • 所有远程操作都需要管理员权限,执行命令的账号必须在远程机器的管理员组里。
  • 远程机器需要开启WinRM服务(PowerShell远程依赖),如果没开,可以先远程执行:
Invoke-Command -ComputerName $targetComputers -ScriptBlock { Enable-PSRemoting -Force }

(如果连WinRM都没开,可能需要先通过组策略或者其他批量工具预先配置)

备注:内容来源于stack exchange,提问作者Kristi Begaj

火山引擎 最新活动