從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

最近碰到一個需求:針對所有電腦卸載某個小軟件,但這個軟件并不是SCCM部署,有的是用戶自己安裝的,有的是系統(tǒng)部署時就已經(jīng)封裝好的,版本繁多,安裝路徑也不一樣!

成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比蓬安網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式蓬安網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋蓬安地區(qū)。費用合理售后完善,十年實體公司更值得信賴。

首先想到的當(dāng)然是用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有卸載的運行文件具體路徑、此文件名及參數(shù):

"C:\Program Files (x86)\Google\Chrome\Application\74.0.3729.131\Installer\setup.exe" --uninstall --system-level --verbose-logging

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

這就是我們要運行的卸載命令,有些軟件只有執(zhí)行文件,并不帶參數(shù),如Teamviewer 只有一個Uninstall.exe,我們可以使用Uninstall.exe /S進行靜默卸載!

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

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

針對注冊表中已有卸載程序和參數(shù)的,上面不用再加參數(shù)數(shù):“/S”

4、 創(chuàng)建腳本:在SoftWare Library\Overview\Scripts中右鍵、Create Script:

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

5、 將PowerShell腳本貼到腳本,下一步,完成!

TeamViewer

$OS = (Get-WmiObject Win32_OperatingSystem).OSArchitecture

????#檢查操作系統(tǒng)版本

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

????#輸出變量結(jié)果,方便查詢分析

}

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

????#輸出變量結(jié)果,方便查詢分析

}

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

6、 核準腳本:在剛創(chuàng)建的腳本上點右鍵、批準

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

在生產(chǎn)環(huán)境中,為了安全,用戶創(chuàng)建的腳本需要第二人來批準(即自己不能批準自己創(chuàng)建的腳本),如果想自己批準自己的創(chuàng)建的腳本,請在進到:Administration\Site Configuration\Sites\Hierarchy Settings,

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

將“Script authors require additional script approver前面的勾取消。

7、 運行腳本:在需要運行的電腦或集全中點右鍵,選擇:Run Script\Next,即開始運行。

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

8、 在Monitoring中也可以查看已運行的腳本匯總結(jié)果 ,在“腳本狀態(tài)”列表中,可以查看在客戶端設(shè)備上運行的每個腳本的結(jié)果。 腳本退出代碼為“0”通常表示腳本已成功運行。

從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件

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

}

當(dāng)然,如果沒有SCCM環(huán)境,也可以嘗試用在AD中調(diào)用上面的腳本!

分享標題:從SCCM中創(chuàng)建并運行Powershell腳本卸載軟件
瀏覽路徑:http://bm7419.com/article20/ijhejo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、用戶體驗、響應(yīng)式網(wǎng)站、網(wǎng)頁設(shè)計公司、定制網(wǎng)站、營銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名