简体   繁体   English

Powershell 循环遍历每个用户配置文件以获取软件版本号,然后创建卸载字符串并运行命令

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

Hoping someone can give me an idea on how to proceed with the remaining script.希望有人能给我一个关于如何继续执行剩余脚本的想法。 The script is to get Version number of Installed Chrome from that build Build a string for the uninstall as shown below.该脚本是从该构建中获取已安装 Chrome 的版本号为卸载构建一个字符串,如下所示。

I'm stuck on the second part, fine on getting the version number.我被困在第二部分,获得版本号很好。

  1. What would the logic be next to then iterate through each user profile to run the setup.exe from C:\Users[username]\appdata\Local\Google\Chrome\Application\90.0.4430.72\Installer.接下来的逻辑是什么,然后遍历每个用户配置文件以从 C:\Users[username]\appdata\Local\Google\Chrome\Application\90.0.4430.72\Installer 运行 setup.exe。 The error I am getting is unrecognized cmdlet on the { & $unin}我得到的错误是 { & $unin} 上无法识别的 cmdlet

Thank you谢谢

#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}
                 
                 }
            
        }

Quote from the docs :文档中引用:

The call operator does not parse strings.调用运算符不解析字符串。 This means that you cannot use command parameters within a string when you use the call operator.这意味着当您使用调用运算符时,您不能在字符串中使用命令参数。

Pass the arguments separately:分别通过 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