Using Output From One Cmdlet to Another Cmd

I'm pretty new to PS so take it easy.   The following query works to get me the IP address of a named interface.

$ActiveIP = Get-NetIPaddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -eq "UniqueName"} | Format-Table IPAddress

Then the $ActiveIP Variable returns the correct information im looking for.  I'm am utterly stuck on how to take that and pipe it correctly to another cmd.

For instance I'd like to automate the DNS config and would pipe that variable to the following...at least that's what I think, but its a no go. I'm sure its something with how im outputting, but then again i'm a noob.

Invoke-Command -ScriptBlock {DNSCMD servername /resetlistenaddresses $ActiveIP}

Any help on straightening me out would be much appreciated.


July 29th, 2015 6:48pm

Hi,

Don't use the Format-* cmdlets if you want to do anything with the data outside of displaying it in the console. Use Select-Object instead.

Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 7:03pm

I like Mike!

Don't be a fool.  Use the correct tool.

$ActiveIP=(Get-NetIPaddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -eq "UniqueName"}.IPAddress

In fact why not just use PowerShell?  It is really easy.

$IP=(Get-NetIPAddress -InterfaceAlias wi-fi -AddressFamily ipv4).IPAddress

Nothing but the PowerShell here.

July 29th, 2015 9:19pm

By the bye. We don't use invoke-Command here:

Just do this:

DNSCMD <servername> /resetlistenaddresses $ActiveIP

This command does nothing for addresses on a non dns server.  You will only get errors.

Time to rethink your strategy.

Free Windows Admin Tool Kit Click here and download it now
July 29th, 2015 9:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics