I have a queue-triggered Powershell function app that is trying to run a PowerShell script located on an Azure VM via Invoke-AzVMRunCommand. I'm able to launch the script but the parameters are blank! Here's the Queue triggered Function App, pretty straightforward:
FunctionApp:
# Input bindings are passed in via param block.
param($QueueItem, $TriggerMetadata)
$ErrorActionPreference = "Stop"
try
{
$SasToken = $Env:SasToken
$PDB = $QueueItem['PDB']
$FileName = $QueueItem['FileName']
$StorageAccount = 'https://STORAGENAME.blob.core.windows.net/CONTAINER/'
$BlobURI = "{0}{1}{2}" -f $StorageAccount, $FileName, $sasToken
$ScriptPath = "F:\azCopy\CopyToDump.ps1"
$ScriptFile = "CopyToDump.ps1"
$params = @{
"PDB" = $PDB;
"BlobURI" = $BlobURI
}
# When using "-ScriptPath $ScriptPath", kept getting errors with path:
# "Could not find path F:..." from a thread somewhere on here, they mentioned
# to us this Out-File -InputObject to which I have no understanding!!!
Out-File -InputObject $ScriptPath -FilePath ScriptToRun.ps1
Invoke-AzVMRunCommand `
-ResourceGroupName 'RESOURCE_GROUP' `
-VMName 'VM_NAME' `
-CommandId 'RunPowerShellScript' `
-ScriptPath ScriptToRun.ps1 `
-Parameter @{ PDB = $PDB; BlobURI = $BlobURI }
Remove-Item -Path ScriptToRun.ps1
Write-Host "Done"
} catch {
$_.Exception.Message
}
And here is the script on the VM, and if you hadn't guessed - I'm using azCopy to download a file from a storage account to this VM:
param(
[string]$PDB,
[string]$BlobURI
)
$logFile = "F:\azcopy\Info.txt"
Function Write-Log {
param(
[Parameter(Mandatory = $true)][string] $message,
[Parameter(Mandatory = $false)]
[ValidateSet("INFO", "WARN", "ERROR")]
[string] $level = "INFO"
)
# Create timestamp
$timestamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
# Append content to log file
Add-Content -Path $logFile -Value "$timestamp [$level] - $message"
}
try
{
$folder = switch ($PDB)
{
'QA' {'094D2AA1A909459BA36ABEEA7F7732F6'}
'DEV' {'0B2305B6305547F389F96C800630CD21'}
}
$dpdump = "F:\app\oracle\admin\hs\dpdump\$folder"
Write-Log -level INFO -message "---------------------------"
Write-Log -level INFO -message "Copying: $BlobURI"
Write-Log -level INFO -message "To folder $dpdump"
Write-Log -level INFO -message "---------------------------"
Write-Log -level INFO -message "F:\azCopy\AzCopy.exe copy $BlobURI $dpdump --overwrite=ifsourcenewer --check-md5=FailIfDifferent"
Write-Log -level INFO -message "---------------------------"
& F:\azCopy\AzCopy.exe copy $BlobURI $dpdump --overwrite=ifsourcenewer --check-md5=FailIfDifferent
} catch {
Write-Log -level ERROR -message "Error running script"
Write-Log -level ERROR -message $_.Message
exit -1
}
I've tried:
-Parameter @{ PDB = $PDB; BlobURI = $BlobURI }
-Parameter @{ "PDB" = $PDB; "BlobURI" = $BlobURI }
-Parameter @{ PDB = "$PDB"; BlobURI = "$BlobURI" }
-Parameter @{ "PDB" = "$PDB"; "BlobURI" = "$BlobURI" }
-Parameter $params