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.
-
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
Please sign in to leave a comment.
Comments
2 comments