i'm attempting to write the result of the
$x = [System.Net.Dns]::GetHostAddresses($name) statement into my write-host string but am encounter some issues with getting the result from the function into the output.
here's the relevant code:
Import-Module activedirectory
function fu($name)
{
$x = [System.Net.Dns]::GetHostAddresses($name).value
if ($x -ne $null){
Write-Host{ $x }
}
else{
Write-Host{"Null"}
}
}
Get-ADComputer -SearchBase 'OU=CorpServers,DC=corp,DC=com,DC=net' -Server "corp.com.net" -Filter * -Properties * |ForEach-Object{write-host "add filter filterlist=""L2-Windows Servers"" srcaddr=any dstaddr=$(fu $_.Name) description=""$($_.Name)"""}
currently it just outputs the string as is, but when it reaches the fu subexpression seems to not properly perform the logic and only outputs "$x" literally, where my intent was to have it output the IP of the current obj in the foreach-object statement.
[System.Net.Dns]::GetHostAddresses(<<hostname>>) | Get-Memberdoes not show anyvalueproperty ? You may simply try running this -[System.Net.Dns]::GetHostAddresses(<<hostname>>)first in your ISE / console.function fu()?$x = [System.Net.Dns]::GetHostAddresses($name)|select-object IPAddressToString -expandproperty IPAddressToString?