1

Using PS to create a extension that needs to do the following for right now.

1: Get zip 2: Unzip and copy into directory in C:\Scripts

Here is the PS to install the extension (this does infact create the extension in extensions under the scale set)

$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

Now inside dsc.zip I have a script called configure.ps1 with a function called AzureDscDemo this is where I run into trouble. How do I take the zip file and save to the file path on the server and better yet unzip it.

Configuration AzureDscDemo {
       Node Localhost {
           File DscFile {
               Type = "Directory"
               Ensure = "Present"
               DestinationPath = "C:\Scripts"
              # Copy zip to scripts????
           }
      }
}
Alex D
  • 788
  • 2
  • 11
  • 33

1 Answers1

1

You dont need to download it and unzip it, extension will do that for you. it will also run the function you are specifying from the file and pass in arguments if you supply any.

now if you want to download an additional zip file, you'd need to code for it. but this is how the extensions works:

"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

Downloading a remote file using powershell dsc:

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

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

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • thank you, now thats in-memory how do I also save its contents to c:/scripts? – Alex D Feb 28 '19 at 17:23
  • why? it's saved to extension folder already. what are you trying to achieve with saving it? – 4c74356b41 Feb 28 '19 at 17:24
  • sooner or later that zip will include a massive amount of source code for a project – Alex D Feb 28 '19 at 17:26
  • first of all. you should ship code to the target, you should ship binaries. secondly, this zip should only have configuration. if you want to use dsc, you can have dsc download the binaries – 4c74356b41 Feb 28 '19 at 17:41
  • Awesome, is this how you would recommend shipping large projects though? – Alex D Feb 28 '19 at 18:25
  • makes sense, I am trying to get azure devops working for that but for haste we are going to need to do something like this. I am a bit lost where i am suppose to but `xRemoteFile 'DownloadFile'` in the scripts i orginally posted. – Alex D Feb 28 '19 at 18:55
  • inside your configuration, I've provided a link to example configuration – 4c74356b41 Feb 28 '19 at 18:57