Windows PowerShell Monitor: Execute Local Script File

I'm trying to write a SAM Template for Windows PowerShell Monitor which will leverage a local file for at least some of the data. I'm not getting that to work in Orion. I'm just trying to validate the concept before I spend time writing up something that won't work, so it's just a simple script.

Version 1:
The file on the node which would be executed by the PowerShell Monitor

Write-Host "Message.1: Hello World"
Write-Host "Statistic.1: 1"

The PowerShell Monitor:
$ScriptBlock = Get-Content -Path "C:\Users\Public\test.ps1" | Out-String
Invoke-Expression -Command $ScriptBlock



I thought that perhaps the Write-Host statements might need to be in the Orion component instead, so I tried:
Version 2:
File on the node:

$Val1 = "Hello World"
$Val2 = 1

PowerShell Monitor:
. "C:\Users\Public\test.ps1"  # Dot Sourcing the content

Write-Host ("Message.1: " + $Val1)
Write-Host ("Statistic.1: " + $Val2)



I actually started out with slightly more complex:
Version 3:

$Message = "Hello World"
$Value = 1
Write-Host ("Message.1: " + $Message)
Write-Host ("Statistic.1: " + $Value)

$ScriptBlock = Get-Content -Path "C:\Users\Public\test.ps1" | Out-String
Invoke-Expression -Command $ScriptBlock



I validated that the credential being used by the component has permissions:

Anyone know if this is supported, and if so, what I did wrong?

  • There is a built in template in sam called "Log Parser (Powershell)" that does just that, stores values in a temp file on the Orion server.

    Think this is the main part of that:

    $t = (Get-Childitem env:temp).value
    $file_path = "$t\$usage-$filename-$position"
    if ( Test-Path $file_path )
      { $known_rows = get-content $file_path }
      { $known_rows = 0 }

    So it stores the file in the temp path.

    So yes, it should work.