Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

PDQ command line: args outside of script (PRTG > PDQ)

Hello,

Probably a basic question, but if I have script such as 

Invoke-Command -ComputerName prtgserver.domain.co.uk -ScriptBlock {pdqdeploy.exe Deploy -Package "Wake Up" -Targets $args[0]} -Args $env:COMPUTERNAME 2>&1

How do I edit the script so I can pass the computername argument outside of the script instead? I'm using PRTG, which can send a command when a sensor enters a particular state (eg run a program when endpoint is offline).

In PRTG, I have to specify the ps1 location, file name, then any arguments. PRTG's variable for the computer name is %host

Background
We use PRTG to monitor our infrastructure. PRTG can fire a "notification" when an sensor enters a particular state. For example, for an endpoint, I have a 'Ping' sensor, which goes into a down state when the endpoint is offline. I can create custom notifications which can run a program (powershell, batch file, vbs, etc) when this sensor enters this down state. I have a PDQ package which send a WOL packet, but need to invoke this from PRTG using  the %host variable from PRTG.

Thanks in advance.

0

Comments

2 comments
Date Votes
  • You can use a param block to pass data into a PowerShell script when you call it.

    [CmdletBinding()]
    param (
    [Parameter(Mandatory = $true)]
    [String]$Package,

    [Parameter(Mandatory = $true)]
    [String]$PdqServer,

    [String[]]$Target = $env:COMPUTERNAME
    )

    Invoke-Command -ComputerName $PdqServer -ScriptBlock {PDQDeploy.exe Deploy -Package $Using:Package -Targets $Using:Target}

    Here's a couple examples of calling this script:

    & .\Example.ps1 -Package 'Wake Up' -PdqServer prtgserver.domain.co.uk -Target %host
    & .\Example.ps1 -Package 'Wake Up' -PdqServer prtgserver.domain.co.uk -Target PC1, PC2, PC3
    0
  • Amazing! Thanks Colby. This works perfectly when testing on its own. It doesn't work in PRTG - so I need to take it up with them and see what's happening and try to get the logs.

    I'll post back here with a solution.

     

    0