I am trying to create a .ps1 file with the Azure YAML pipelines powershell task using an inline script;
- task: PowerShell@2
displayName: "Create IIS Log Cleardown script file"
env:
DaysToKeep: ${{ parameters.DaysToKeep }}
inputs:
targetType: 'inline'
script: |
$DaysToKeep = $env:DaysToKeep
Set-Content -Path C:\scripts\CleanupScript.ps1 @"
$logPath = 'C:\inetpub\logs\LogFiles'
$daysKept = $DaysToKeep
$retentionDate = $(Get-Date).AddDays(-$daysToKeep)
..."@
On the target server the file is updated however all the powershell variables have been stripped/replaced in the file;
= 'C:\inetpub\logs\LogFiles'
= 3
= .AddDays(-3)
The powershell script variables $logPath, $daysKept and $retentionDate have been removed.
I have tried escaping the script several ways with no luck, is there any way to fully escape this script from variable substitution whilst still retaining the single and double quotes required in the powershell script?