Little help with a script

Hello guys,

I'm hoping that you guys can give me a little bit of help with a script that i'm trying to write, i'm a beginner when it comes to scripting so you're help it's greatly appreciated. The purpose of the script below is to through to a list of different DNS domain names and search for certain criteria and then display on the screen or file for me, the problem that I'm running into is that I don't know how to display or write to file the variable $dnszone to the screen so that when I get the output for hostnames I can tell from which DNS zone it came from.

Here is the script thus far

$dnszones = Get-Content "C:\all_dnz_zones.txt"
$IPv4Address = "10.10.*"
foreach ($dnszone in $dnszones) {Get-DnsServerResourceRecord -ZoneName $dnszone -ComputerName htxdc01 | Where-Object {$_.RecordData.IPv4Address -like $IPv4Address}}

This is the output that I see write now, i'm missing the $dnszone names :(


  • Edited by Delmiroc Sunday, May 24, 2015 7:17 PM
May 24th, 2015 7:15pm

Hello guys,

I'm hoping that you guys can give me a little bit of help with a script that i'm trying to write, i'm a beginner when it comes to scripting so you're help it's greatly appreciated. The purpose of the script below is to through to a list of different DNS domain names and search for certain criteria and then display on the screen or file for me, the problem that I'm running into is that I don't know how to display or write to file the variable $dnszone to the screen so that when I get the output for hostnames I can tell from which DNS zone it came from.

Here is the script thus far

$dnszones = Get-Content "C:\all_dnz_zones.txt"
$IPv4Address = "10.10.*"
foreach ($dnszone in $dnszones) {Get-DnsServerResourceRecord -ZoneName $dnszone -ComputerName htxdc01 | Where-Object {$_.RecordData.IPv4Address -like $IPv4Address}}

This is the output that I see write now, i'm missing the $dnszone names :(


Try this, maybe

$dnszones = Get-Content "C:\all_dnz_zones.txt"
$IPv4Address = "10.10.*"
foreach ($dnszone in $dnszones) {$zone = $dnszone;Get-DnsServerResourceRecord -ZoneName $dnszone -ComputerName htxdc01 | Where-Object {$_.RecordData.IPv4Address -like $IPv4Address}, select @{n="Dnszone";e={$dnszone}},*}

I tested it on another cmdlet, but it might work.. (I could mess up some bracers though)

$servers = "server1","server2"
foreach ($server in $servers) {$srv = $server;gwmi win32_bios -computername $server |select @{n="server";e={$srv}},*} 

Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 7:59am

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

Other recent topics Other recent topics