簡體   English   中英

Powershell 循環遍歷每個用戶配置文件以獲取軟件版本號,然后創建卸載字符串並運行命令

[英]Powershell to Loop through each user profile to get Version number of software and then create uninstall string and run the command

希望有人能給我一個關於如何繼續執行剩余腳本的想法。 該腳本是從該構建中獲取已安裝 Chrome 的版本號為卸載構建一個字符串,如下所示。

我被困在第二部分,獲得版本號很好。

  1. 接下來的邏輯是什么,然后遍歷每個用戶配置文件以從 C:\Users[username]\appdata\Local\Google\Chrome\Application\90.0.4430.72\Installer 運行 setup.exe。 我得到的錯誤是 { & $unin} 上無法識別的 cmdlet

謝謝

#UserHives - Find all the user profiles in the registry
$UserHives = Get-ChildItem Registry::HKEY_USERS\ |Where-Object {$_.Name -match '^HKEY_USERS\\S-1-5-21-[\d\-]+$'}
$UserProfile = $Env:USERPROFILE

#
foreach($user in $UserHives)


{
    #1.Get Version Of chrome
     
     #1. PATH TO SEARCH FOR
     $Path = Join-Path $user.PSPath "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome"

            If (Test-Path $Path){
                 $GetVersion = Get-ItemProperty -Path $Path | Select-Object -Property Version
                 $VersionInstalled = $GetVersion.Version

                 

                 #create uninstallstring
                 $UninString = "\Google\Chrome\Application\$VersionInstalled\Installer\setup.exe --uninstall --Channel --chrome --force-uninstall"
                 $unin = $UserProfile + "" + $UninString

                 If($VersionInstalled){ & $unin}
                 
                 }
            
        }

文檔中引用:

調用運算符不解析字符串。 這意味着當您使用調用運算符時,您不能在字符串中使用命令參數。

分別通過 arguments:

$uninArgs = "--uninstall", "--Channel", "--chrome", "--force-uninstall"
$uninExe = "$UserProfile\Google\Chrome\Application\$VersionInstalled\Installer\setup.exe"
if ($VersionInstalled) {
    & $uninExe $uninArgs
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM