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
It's because on the remote computer where your scriptblock is, it has no idea what $ip is. Change your command to this:
That will send the value of the $ip variable to the remote console.
Also, I don't think you want to pipe into Invoke-Command, separate it into to distinct lines:
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