Azure DSC extention. How to use additional items in a archive

81 Views Asked by At

I'm trying to use DSC extension for Azure VM. I have created zip archive with main PS file, and included additional archive to the main archive, with couple additional files enter image description here After DSC extension is applied,I see my additional archive in DSC dirrectory enter image description here

My question is, how to obtain that path C:\Packages\Plugins\Microsoft.Powershell.DSC\2.83.5\DSCWork\IISInstall.0 for future use in my DSC script? I tried to find any env variable, that contains that path? but futile. Maybe do you guys know how to manage it? I appreciate any help. thank you all

1

There are 1 best solutions below

0
Imran On

I have created DSC extension created, .ps1 file in PowerShell and place the iis Install.ps1 script on the specified VM and it executed successfully like below:

$resourceGroup = 'dscVmDemo'
$vmName = 'myVM'
$storageName = 'demostorage'
#Publish the configuration script to user storage
Publish-AzVMDscConfiguration -ConfigurationPath .\iisInstall.ps1 -ResourceGroupName $resourceGroup -StorageAccountName $storageName -force
#Set the VM to run the DSC configuration
Set-AzVMDscExtension -Version '2.80' -ResourceGroupName $resourceGroup -VMName $vmName -ArchiveStorageAccountName $storageName -ArchiveBlobName 'iisInstall.ps1.zip' -AutoUpdate -ConfigurationName 'IISInstall'

enter image description here

File uploaded automatically in storage account:

enter image description here

In your scenario, to obtain that path future in DSC script use $env:TEMP environment variable. A temporary folder with a name starts with "DSC" is created by the DSC extension in the $env:TEMP directory. You can save files you require for your DSC script in this folder.

$DSCWorkPath = Join-Path $env:TEMP "DSC" -ChildPath "Microsoft.Powershell.DSC\2.83.5\DSCWork\IISInstall.0"

If you are hardcoding a specific version number or subdirectory in your DSC script values could potentially change in the future.

You can use to dynamically resolve the DSC working directory path using below script:

$extensionPath = $env:ProgramData + '\Packages\Plugins\Microsoft.Powershell.DSC\'
$versionFolders = Get-ChildItem -Path $extensionPath | Sort-Object -Property Name -Descending
$latestVersionFolder = $versionFolders[0].Name
$workingDirectory = Join-Path -Path $extensionPath -ChildPath ($latestVersionFolder + '\DSCWork\IISInstall.0')

This way, even if the version number changes, your script will automatically use the latest version available.

Reference:

Desired State Configuration for Azure overview - Azure Virtual Machines | Microsoft Learn