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.

pipe computer IP into -Targets in powershell

Hello, I am testing running PDQ deployments from PS.  I want to pipe the target computer's IP into the command.  Here is what I have, but it does not apply the $ip value to -Targets

$ip = (($ipV4 = Test-Connection -ComputerName (hostname) -Count 1 | Select -ExpandProperty IPV4Address).IPAddressToString) |
Invoke-Command -ComputerName "pdq" -ScriptBlock {
pdqdeploy Deploy -Package "test message" -Targets "$ip"
}

0

Comments

3 comments
Date Votes
  • It's because on the remote computer where your scriptblock is, it has no idea what $ip is. Change your command to this:

     

    Invoke-Command -Computername "pdq" -ScriptBlock { pdqdeploy Deploy -Package "Test message" -Targets $args[0] } -ArgumentList $ip

    That will send the value of the $ip variable to the remote console.

    0
  • Also, I don't think you want to pipe into Invoke-Command, separate it into to distinct lines:

    $ip = (($ipV4 = Test-Connection -ComputerName (hostname) -Count 1 | Select -ExpandProperty IPV4Address).IPAddressToString)

    Invoke-Command -Computername "pdq" -ScriptBlock { pdqdeploy Deploy -Package "Test message" -Targets $args[0] } -ArgumentList $ip
    0
  • perfect, thanks so much.  I wanted to use IP instead of computer name in case this runs on subnet away from PDQ Server and I don't want to wait for AD to update

    0