DSC/WriteProperties/WriteProperties.ps1

Configuration WriteProperties
{
    param(
        [Parameter(Mandatory = $false)]
        [string]
        $VMName,
        [Parameter(Mandatory = $false)]
        [string]
        $ScaleSetName,
        [Parameter(Mandatory = $true)]
        [string]
        $ResourceGroupName,
        [Parameter(Mandatory = $true)]
        [string]
        $StorageAccountName,
        [Parameter(Mandatory = $true)]
        [string]
        $KeyVaultName,
        [Parameter(Mandatory = $true)]
        [string]
        $StorageTableNameSetup,
        [Parameter(Mandatory = $true)]
        [string]
        $StorageTableNameEnvironments,
        [Parameter(Mandatory = $true)]
        [string]
        $StorageTableNameEnvironmentDefaults,
        [Parameter(Mandatory = $true)]
        [string]
        $StorageTableNameInfrastructureData
    )

    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'

    Node localhost
    {
        Script WriteProperties {
            SetScript  = {
                $targetFolder = 'C:\Install\AutoUpdate'
                New-Item -ItemType Directory -Path $targetFolder -ErrorAction SilentlyContinue | Out-Null
                $fullscriptpath = Join-Path $targetFolder 'Properties.ps1'
                $content = "
                            `$VMName = '$VMName'
                            `$ScaleSetName = '$ScaleSetName'
                            `$ResourceGroupName = '$ResourceGroupName'
                            `$StorageAccountName = '$StorageAccountName'
                            `$KeyVaultName = '$KeyVaultName'
                            `$StorageTableNameSetup = '$StorageTableNameSetup'
                            `$StorageTableNameEnvironments = '$StorageTableNameEnvironments'
                            `$StorageTableNameEnvironmentDefaults = '$StorageTableNameEnvironmentDefaults'
                            `$StorageTableNameInfrastructureData = '$StorageTableNameInfrastructureData'
                            "

                Set-Content -Path $fullscriptpath -Value $content
            }
            TestScript = { 
                $targetFolder = 'C:\Install\AutoUpdate'    
                $fullscriptpath = Join-Path $targetFolder 'Properties.ps1'
                Test-Path $fullscriptpath
            }
            GetScript  = { 
                $targetFolder = 'C:\Install\AutoUpdate'    
                $fullscriptpath = Join-Path $targetFolder 'Properties.ps1'                
                @{ Result = (Get-Content $fullscriptpath) }
            }
        }
    }
}

<#
$writeProperties = {
    param(
        [Parameter(Mandatory = $false, Position = 1)]
        [string]
        $VMName,
        [Parameter(Mandatory = $false, Position = 2)]
        [string]
        $ScaleSetName,
        [Parameter(Mandatory = $true, Position = 3)]
        [string]
        $ResourceGroupName,
        [Parameter(Mandatory = $true, Position = 4)]
        [string]
        $StorageAccountName,
        [Parameter(Mandatory = $true, Position = 5)]
        [string]
        $KeyVaultName,
        [Parameter(Mandatory = $true, Position = 6)]
        [string]
        $StorageTableNameSetup,
        [Parameter(Mandatory = $true, Position = 7)]
        [string]
        $StorageTableNameEnvironments,
        [Parameter(Mandatory = $true, Position = 8)]
        [string]
        $StorageTableNameEnvironmentDefaults,
        [Parameter(Mandatory = $true, Position = 9)]
        [string]
        $StorageTableNameInfrastructureData
    )
    $targetFolder = 'C:\Install\AutoUpdate'
    New-Item -ItemType Directory -Path $targetFolder -ErrorAction SilentlyContinue | Out-Null
    $fullscriptpath = Join-Path $targetFolder 'Properties.ps1'
     
    $content = "
    `$VMName = '$VMName'
    `$ScaleSetName = '$ScaleSetName'
    `$ResourceGroupName = '$ResourceGroupName'
    `$StorageAccountName = '$StorageAccountName'
    `$KeyVaultName = '$KeyVaultName'
    `$StorageTableNameSetup = '$StorageTableNameSetup'
    `$StorageTableNameEnvironments = '$StorageTableNameEnvironments'
    `$StorageTableNameEnvironmentDefaults = '$StorageTableNameEnvironmentDefaults'
    `$StorageTableNameInfrastructureData = '$StorageTableNameInfrastructureData'
    "
    Set-Content -Path $fullscriptpath -Value $content
}
#>