locked
Little help with a script RRS feed

  • Question

  • 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 :(

    Sunday, May 24, 2015 7:19 PM

Answers

  • Sorry - there is a typo.

    It must belike this.

    $dnszones = Get-Content C:\all_dnz_zones.txt
    foreach($dnszone in $dnszones){
        Get-DnsServerResourceRecord -ZoneName $dnszone -ComputerName htxdc01 | 
           Where-Object{ 
                $_.RecordData.IPv4Address -match '^10\.10\.'
        } |
        select *, @{N='DNSZone';E={$dnszone}}
    }

    Do not attempt to change theformatting until you understand.


    \_(ツ)_/

    • Marked as answer by Delmiroc Monday, May 25, 2015 3:13 PM
    Monday, May 25, 2015 5:50 AM

All replies

  • 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
    • Merged by AnnaWY Tuesday, May 26, 2015 7:23 AM duplicate
    Sunday, May 24, 2015 7:15 PM
  • Just add it to the records:

    $dnszones = Get-Content C:\all_dnz_zones.txt
    foreach($dnszone in $dnszones){
        Get-DnsServerResourceRecord -ZoneName $dnszone -ComputerName htxdc01 | 
           Where-Object{ 
                $_.RecordData.IPv4Address -match '^10\.10\.'
        } |
        select *, @{N='DNSZone';E={$dnszone}}
    }


    \_(ツ)_/


    • Edited by jrv Monday, May 25, 2015 5:51 AM
    Sunday, May 24, 2015 8:21 PM
  • Duplicate post.  Please don't post multiple times as it will not get you a faster answer.

    \_(ツ)_/

    Sunday, May 24, 2015 8:26 PM
  • thank you for your response, I added the line as suggested but it doesn't seem to work, the script runs but I don't see any output on the screen (blank). do you have any other suggestions?

    $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
    }
     select *, @{N='DNSZone';E={$dnszone}
     }

    I appreciate the help, thanks again.

    Delmiro

    Monday, May 25, 2015 5:44 AM
  • Sorry - there is a typo.

    It must belike this.

    $dnszones = Get-Content C:\all_dnz_zones.txt
    foreach($dnszone in $dnszones){
        Get-DnsServerResourceRecord -ZoneName $dnszone -ComputerName htxdc01 | 
           Where-Object{ 
                $_.RecordData.IPv4Address -match '^10\.10\.'
        } |
        select *, @{N='DNSZone';E={$dnszone}}
    }

    Do not attempt to change theformatting until you understand.


    \_(ツ)_/

    • Marked as answer by Delmiroc Monday, May 25, 2015 3:13 PM
    Monday, May 25, 2015 5:50 AM
  • 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}},*} 

    Monday, May 25, 2015 11:58 AM
  • Thanks! that did it.
    Monday, May 25, 2015 3:14 PM
  • Hi Delmiroc,

    I find you got the answer in the thread below, so I will colse this one:

    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/901fd4c0-6d08-4618-bd2c-bfd4d0011f99/little-help-with-a-script?forum=ITCG#50fb32eb-4756-41fc-9e1d-1d05ad24afe7

    Best Regards,

    Anna Wang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

    Tuesday, May 26, 2015 7:21 AM