Azure VMSS Powershell 扩展从 url 复制文件

Azure VMSS Powershell extension copying files from url

使用 PS 创建一个扩展,现在需要执行以下操作。

1: 获取 zip 2:解压并复制到目录C:\Scripts

这里是 PS 安装扩展(这实际上会在规模集下的扩展中创建扩展)

$dscConfig = @{
  "wmfVersion" = "latest";
  "configuration" = @{
    "url" = "https://foo.blob.core.windows.net/dsc.zip";
    "script" = "configure.ps1";
    "function" = "AzureDscDemo";
  };
}

$vmss = Get-AzVmss `
                -ResourceGroupName "FooVmssResource" `
                -VMScaleSetName "FooVmss"

$vmss = Add-AzVmssExtension `
    -VirtualMachineScaleSet $vmss `
    -Publisher Microsoft.Powershell `
    -Type DSC `
    -TypeHandlerVersion 2.24 `
    -Name "DSC" `
    -Setting $dscConfig

Update-AzVmss `
    -ResourceGroupName "FooVmssResource" `
    -Name "FooVmss"  `
    -VirtualMachineScaleSet $vmss

现在 dsc.zip 我有一个名为 configure.ps1 的脚本,其中有一个名为 AzureDscDemo 的函数,这就是我 运行 遇到麻烦的地方。如何将 zip 文件保存到服务器上的文件路径并更好地解压缩它。

Configuration AzureDscDemo {
       Node Localhost {
           File DscFile {
               Type = "Directory"
               Ensure = "Present"
               DestinationPath = "C:\Scripts"
              # Copy zip to scripts????
           }
      }
}

您不需要下载并解压缩,扩展程序会为您完成。它还将 运行 您从文件中指定的函数,并在您提供任何参数时传递参数。

现在,如果您想下载其他 zip 文件,则需要为其编码。但这是扩展的工作原理:

"url" = "https://foo.blob.core.windows.net/dsc.zip" <<< get zip from this url and unzip it to a special folder on the vm
"script" = "configure.ps1" <<< load this file into memory
"function" = "AzureDscDemo" <<< call this function from inside the file

正在使用 powershell dsc 下载远程文件:

    xRemoteFile 'DownloadFile'
    {
        DestinationPath = $DestinationPath
        Uri             = $Uri
        UserAgent       = $UserAgent
        Headers         = $Headers
    }

https://github.com/PowerShell/xPSDesiredStateConfiguration/blob/dev/Examples/xRemoteFile_DownloadFileConfig.ps1