【问题标题】:Powershell script to install Azure Service Fabric SDK, runtime and tools silently用于静默安装 Azure Service Fabric SDK、运行时和工具的 Powershell 脚本
【发布时间】:2018-11-11 21:53:01
【问题描述】:

我正在尝试编写一个脚本来将安装 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


    【解决方案1】:

    我知道这并不完全符合您的要求,但您可以使用 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 并运行安装命令即可。

    更多关于WebPICMDhere

    【讨论】:

      【解决方案2】:

      要补充上面的答案,如果 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 参数值:

      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;
      

      那么在字符串中使用变量也比较容易。

      【讨论】:

        猜你喜欢
        • 2018-01-19
        • 1970-01-01
        • 1970-01-01
        • 2019-02-19
        • 2021-10-12
        • 1970-01-01
        • 2016-09-28
        • 2019-05-10
        • 1970-01-01
        相关资源
        最近更新 更多