问题
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????
}
}
}
回答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
来源:https://stackoverflow.com/questions/54930633/azure-vmss-powershell-extension-copying-files-from-url