Powershell脚本以静默方式安装Azure Service Fabric SDK,运行时和工具

问题描述 投票:2回答:2

我正在尝试编写一个脚本,以将安装Azure Service Fabric SDK,运行时和工具下载到几个服务器中。

我的问题是安装程序提供的here是一个Web安装程序,并且不支持静默模式。

我发现一个人解决了这个问题here。他的代码:

# Install Service Fabric Runtime
Invoke-WebRequest "http://download.microsoft.com/download/3/2/1/3217654F-6882-4CEA-BD51-49287EDECE9B/MicrosoftServiceFabric.6.0.232.9494.exe" -OutFile "C:\ServiceFabricRuntime.exe" -UseBasicParsing; \
Start-Process "C:\ServiceFabricRuntime.exe" -ArgumentList '/AcceptEULA', '/QUIET' -NoNewWindow -Wait; \
rm "C:\ServiceFabricRuntime.exe"

# Install Service Fabric SDK
Invoke-WebRequest "http://download.microsoft.com/download/3/2/1/3217654F-6882-4CEA-BD51-49287EDECE9B/MicrosoftServiceFabricSDK.2.8.232.msi" -OutFile "C:\ServiceFabricSDK.msi" -UseBasicParsing; \
Start-Process "msiexec" -ArgumentList '/i', 'C:\ServiceFabricSDK.msi', '/passive', '/quiet', '/norestart', '/qn' -NoNewWindow -Wait; \
rm "C:\ServiceFabricSDK.msi"

正如你所看到的,他正在使用直接链接到.msi安装程序(以及其他人正在做其他线程,如these two答案。)。

所以我的问题是,如何使用这些安装程序的最新版本直接链接到msi?

接下来的问题是,是否有一个通用链接会自动下载这些工具的最新版本?

提前致谢。

powershell azure azure-service-fabric
2个回答
4
投票

我知道这不是你要求的,但你可以使用Web Platform Installer Command Line静默安装WebPI产品。我的想法是下载WebPICMD并从cmd行运行Service Fabric SDK的安装。 powershell脚本可能如下所示:

Invoke-WebRequest "https://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi" -OutFile "C:\WebPlatformInstaller.msi" -UseBasicParsing;
Start-Process "msiexec" -ArgumentList '/i', 'C:\WebPlatformInstaller.msi', '/passive', '/quiet', '/norestart', '/qn' -NoNewWindow -Wait; 
rm "C:\WebPlatformInstaller.msi"

WebPICMD.exe /Install /Products:MicrosoftAzure-ServiceFabric-CoreSDK /AcceptEULA

产品MicrosoftAzure-ServiceFabric-CoreSDK将默默安装最新版本的Service Fabric SDKService Fabric Runtime

如果你想安装与WebPI不同的东西:

WebPICMD.exe /List /ListOption:All

此命令将列出所有可用产品,只需获取产品的ID并运行install命令。

关于WebPICMD here的更多信息。


1
投票

要添加上面的答案,如果WebPlatformCMD为您提供Windows的UAC同意窗口问题,您可以使用PSEXEC工具将安装程序作为系统帐户运行,从而避免该问题。

示例代码:

 Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkId=287166" -OutFile "$env:temp\WebPlatformInstaller_amd64_en-US.msi" -UseBasicParsing

 Start-Process "msiexec" -ArgumentList "/i $env:temp\WebPlatformInstaller_amd64_en-US.msi /passive /quiet /norestart /qn" -NoNewWindow -Wait

 $psToolsPath = "$env:temp\pstools"
 New-Item $psToolsPath -ItemType directory -force -erroraction silentlycontinue
 Invoke-WebRequest -Uri https://download.sysinternals.com/files/PSTools.zip -OutFile $psToolsPath\PSTools.zip

 Expand-Archive "$psToolsPath\PSTools.zip" $psToolsPath -force
 cd $psToolsPath
 Start-Process psexec64 -ArgumentList "-s /accepteula WebPICMD.exe /Install /Products:MicrosoftAzure-ServiceFabric-CoreSDK /AcceptEULA"

关于SteppingRazor上面的答案的小注释。

你可以像这样简化ArgumentList Parameter值:

Start-Process "msiexec" -ArgumentList "/i C:\WebPlatformInstaller.msi /passive /quiet /norestart /qn -NoNewWindow -Wait

代替

Start-Process "msiexec" -ArgumentList '/i', 'C:\WebPlatformInstaller.msi', '/passive', '/quiet', '/norestart', '/qn' -NoNewWindow -Wait;

然后在字符串中使用变量也更容易。

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