最近碰到一个需求:针对所有电脑卸载某个小软件,但这个软件并不是SCCM部署,有的是用户自己安装的,有的是系统部署时就已经封装好的,版本繁多,安装路径也不一样!
首先想到的当然是用Powershell来做,先后测试了用Get-apppacke\get-appxpacke, Get-WmiObject -Class win32_product等几种方法都不行,最后用找注册表中的UninstallString的方式解决!
方法如下:
1、 先用PowerShell定位到注册表位置,
X86 Script:
Set-Location HKLM:\software\microsoft\Windows\Currentversion\uninstall
X64 Script:
Set-Location HKLM:\software\WOW6432Node\microsoft\Windows\Currentversion\uninstall
2、 查询到软件安装后在注册表Uninstall中的名称,如:Chrome,在Uninstall中的Childitem名为:Google Chrome,其中Uninstallstring有卸载的运行文件具体路径、此文件名及参数:
"C:\Program Files (x86)\Google\Chrome\Application\74.0.3729.131\Installer\setup.exe" --uninstall --system-level --verbose-logging
这就是我们要运行的卸载命令,有些软件只有执行文件,并不带参数,如Teamviewer 只有一个Uninstall.exe,我们可以使用Uninstall.exe /S进行静默卸载!
3、 完整的PS脚本如下:
Set-Location
HKLM:\software\WOW6432Node\microsoft\Windows\Currentversion\uninstall
# 指定注册表的位置
$UninstallTeamviewer = get-childitem -path *Teamviewer* | get-itemproperty | %{$_.Uninstallstring}
# 查找卸载命令并赋值给变量:$UninstallTeamviewer
start $UninstallTeamviewer /S
#Powershell 中运行卸载命令 :$UninstallTeamviewer
针对注册表中已有卸载程序和参数的,上面不用再加参数数:“/S”
4、 创建脚本:在SoftWare Library\Overview\Scripts中右键、Create Script:
5、 将PowerShell脚本贴到脚本,下一步,完成!
TeamViewer
$OS = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
# 检查操作系统版本
if ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "32-bit"){
#32 Bit 运 行以下步骤
Set-Location HKLM:\software\microsoft\Windows\Currentversion\uninstall
# 指定以下注册表位置
$UninstallTeamviewer = get-childitem -path *Teamviewer* | get-itemproperty | %{$_.Uninstallstring}
# 查找卸载命令并赋值给变量:$UninstallTeamviewer
start $UninstallTeamviewer /S
#Powershell 中运行卸载命令:$UninstallTeamviewer
$UninstallTeamviewer
# 输出变量结果,方便查询分析
}
else{
#64 Bit 运行以下步骤
Set-Location HKLM:\software\WOW6432Node\microsoft\Windows\Currentversion\uninstall
# 指定以下注册表位置
$UninstallTeamviewer = get-childitem -path *Teamviewer* | get-itemproperty | %{$_.Uninstallstring}
# 查找卸载命令并赋值给变量:$UninstallTeamviewer
start $UninstallTeamviewer /S
#Powershell 中运行卸载命令:$UninstallTeamviewer
$UninstallTeamViewer
# 输出变量结果,方便查询分析
}
6、 核准脚本:在刚创建的脚本上点右键、批准
在生产环境中,为了安全,用户创建的脚本需要第二人来批准(即自己不能批准自己创建的脚本),如果想自己批准自己的创建的脚本,请在进到:Administration\Site Configuration\Sites\Hierarchy Settings,
将“Script authors require additional script approver前面的勾取消。
7、 运行脚本:在需要运行的电脑或集全中点右键,选择:Run Script\Next,即开始运行。
8、 在Monitoring中也可以查看已运行的脚本汇总结果 ,在“脚本状态”列表中,可以查看在客户端设备上运行的每个脚本的结果。 脚本退出代码为“0”通常表示脚本已成功运行。
9、 也可以晚点再去软件报告里进行查询!
10、 如果针对某个软件是使用MIS封装包安装的,Uninstall值会是“MsiExec.exe /I {23170F69-40C1-2701-1602-000001000000}“,就要改另一种PowerShell方式,例:
if ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "32-bit"){
#32 Bit 7zip X32 1602 {23170F69-40C1-2701-1602-000001000000}
$script = { invoke-expression "msiexec /qn /x '{23170F69-40C1-2701-1602-000001000000}' "}
Invoke-Command -ScriptBlock $script
$script
}else{
#64 Bit 7zip X64 1602 {23170F69-40C1-2702-1602-000001000000}
$script = { invoke-expression "msiexec /qn /x '{23170F69-40C1-2702-1602-000001000000}' "}
Invoke-Command -ScriptBlock $script
$script
}
当然,如果没有SCCM环境,也可以尝试用在AD中调用上面的脚本!
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 彻底卸载干净oracle 11g
- [译]如何从 Ubuntu 卸载 Redis
- 云设计模式之: 网关卸载模式
- 那些你应该考虑卸载的 VSCode 扩展
- Debian完全卸载清理MySQL服务器
- Mac中mongoDB的安装与卸载步骤详解
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
算法导论(原书第3版)
Thomas H.Cormen、Charles E.Leiserson、Ronald L.Rivest、Clifford Stein / 殷建平、徐云、王刚、刘晓光、苏明、邹恒明、王宏志 / 机械工业出版社 / 2012-12 / 128.00元
在有关算法的书中,有一些叙述非常严谨,但不够全面;另一些涉及了大量的题材,但又缺乏严谨性。本书将严谨性和全面性融为一体,深入讨论各类算法,并着力使这些算法的设计和分析能为各个层次的读者接受。全书各章自成体系,可以作为独立的学习单元;算法以英语和伪代码的形式描述,具备初步程序设计经验的人就能看懂;说明和解释力求浅显易懂,不失深度和数学严谨性。 全书选材经典、内容丰富、结构合理、逻辑清晰,对本科......一起来看看 《算法导论(原书第3版)》 这本书的介绍吧!