需要通过Powershell安装Microsoft Visual C++ 2015-2022

问题描述 投票:0回答:1

我必须通过 powershell 安装以下 Visual C++ 软件。

  • VC_redist_2015-2022x64
  • VC_redist_2015-2022x86

我必须首先检查我的服务器上是否安装了 Visual C++ x64 和 x86。如果已安装代码,则必须跳过安装部分,否则必须安装 Visual C++ x64 和 x84。我有一个 powershell 代码无法正常工作。我正在尝试通过名字来缩短。但我的代码不起作用。

有人可以帮我解决吗

我期待您的来信。

$MSRedistributable = Get-WmiObject -Query "Select * from Win32_Product where name = 'Microsoft Visual C++'"
$MSRedistributableInstaller = "C:\Software"

Write-host "`nStaring Installation of Microsoft Visual C++ 2015-2022"
if (!($MSRedistributable.name))
{
Write-host "Installing Microsoft Visual C++."
Start-Process -Filepath "$($MSRedistributableInstaller)\VC_redist_2015-2022x64" -Argumentlist "/Q" -wait
Start-Process -Filepath "$($MSRedistributableInstaller)\VC_redist_2015-2022x86" -Argumentlist "/Q" -wait
write-host "Microsoft Visual C++ installed successfully."
}
else
{
write-host "$($MSRedistributable.name) appears to be installed already.  Skipping."
}
windows powershell powershell-2.0
1个回答
0
投票

我对你的问题有一个猜测。在代码中的第 1 行,查询语句应从 '=' 修改为 'like',类似于以下示例: `(base) PS C:\Users zcbz> Get-WmiObject -Query "从 Win32_Product 选择 *,其中名称 = 'Microsoft Visual C++'" (基)PS C:\Users zcbz> Get-WmiObject -Query“从 Win32_Product 选择 *,其中名称如“Microsoft Visual C++”” (base) PS C:\Users zcbz> Get-WmiObject -Query "从 Win32_Product 中选择 *,其中名称如 'Microsoft Visual C++%'"

识别号:{1D8E6291-B0D5-35EC-8441-6616F567A0F7} 名称:Microsoft Visual C++ 2010 x64 可再发行组件 - 10.0.40219 供应商:微软公司 版本:10.0.40219 说明文字:Microsoft Visual C++ 2010 x64 可再发行 - 10.0.40219

识别号码:{ad8a2fa1-06e7-4b0d-927d-6e54b3d31028} 名称:Microsoft Visual C++ 2005 可再发行组件 (x64) 供应商:微软公司 版本:8.0.61000 说明文字:Microsoft Visual C++ 2005 Redistributable (x64)

识别号码:{8122DAB1-ED4D-3676-BB0A-CA368196543E} 名称:Microsoft Visual C++ 2013 x86 最低运行时间 - 12.0.40664 供应商:微软公司 版本:12.0.40664 说明文字:Microsoft Visual C++ 2013 x86 最短运行时间 - 12.0.40664`

© www.soinside.com 2019 - 2024. All rights reserved.