ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell issues with splitting or trimming data in a $string

    IT Discussion
    2
    7
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • computerchipC
      computerchip
      last edited by computerchip

      I have team member who needs a powershell script to pull from a list of 3500 domains, and get the whois data for each and output to a CSV he can do filtering and pivot tables on. I am using the whois.exe tool from sysinternals to pull the data into a $string and I am trying to trim all the data out of the string after a set of characters and I can't seem to get it to work using .split or .trim. It always just outputs the entire returned results. Any ideas?

      CODE:

      $domains = Get-Content C:\temp\chip\domains.txt

      foreach($domain in $domains)
      {
      $domain | Out-File -filepath C:\temp\chip\whois_data.csv -append
      $data = .\WhoIs.exe $domain.split("DNSSEC:")[0]
      $data[0] | Out-File -filepath C:\temp\chip\whois_data.csv -append
      Write-Host "Query complete for" $domain
      }

      1 Reply Last reply Reply Quote 0
      • dafyreD
        dafyre
        last edited by

        What is the output of the whois.exe line?

        computerchipC 1 Reply Last reply Reply Quote 0
        • computerchipC
          computerchip @dafyre
          last edited by

          @dafyre
          I just have google.com in the domains.txt now for testing purposes, this it the output on the one domain.

          google.com
          Whois v1.14 - Domain information lookup
          Copyright (C) 2005-2016 Mark Russinovich
          Sysinternals - www.sysinternals.com
          Connecting to COM.whois-servers.net...
          Domain ID: 2138514_DOMAIN_COM-VRSN
          Registrar WHOIS Server: whois.markmonitor.com
          Registrar URL: http://www.markmonitor.com
          Updated Date: 2011-07-20T16:55:31Z
          Creation Date: 1997-09-15T04:00:00Z
          Registry Expiry Date: 2020-09-14T04:00:00Z
          Registrar: MarkMonitor Inc.
          Registrar IANA ID: 292
          Registrar Abuse Contact Email: [email protected]
          Registrar Abuse Contact Phone: +1.2083895740
          Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
          Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
          Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
          Domain Status: serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited
          Domain Status: serverTransferProhibited https://icann.org/epp#serverTransferProhibited
          Domain Status: serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited
          Name Server: NS1.GOOGLE.COM
          Name Server: NS2.GOOGLE.COM
          Name Server: NS3.GOOGLE.COM
          Name Server: NS4.GOOGLE.COM
          DNSSEC: unsigned
          URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/

          Last update of whois database: 2017-10-17T18:17:02Z <<<
          For more information on Whois status codes
          NOTICE: The expiration date displayed in this record is the date the
          registrar's sponsorship of the domain name registration in the registry is
          currently set to expire. This date does not necessarily reflect the expiration
          date of the domain name registrant's agreement with the sponsoring
          registrar. Users may consult the sponsoring registrar's Whois database to
          view the registrar's reported date of expiration for this registration.
          TERMS OF USE: You are not authorized to access or query our Whois
          database through the use of electronic processes that are high-volume and
          automated except as reasonably necessary to register domain names or
          modify existing registrations; the Data in VeriSign Global Registry
          Services' ("VeriSign") Whois database is provided by VeriSign for
          information purposes only
          about or related to a domain name registration record. VeriSign does not
          guarantee its accuracy. By submitting a Whois query
          by the following terms of use: You agree that you may use this Data only
          for lawful purposes and that under no circumstances will you use this Data
          to: (1) allow
          unsolicited
          or facsimile; or (2) enable high volume
          that apply to VeriSign (or its computer systems). The compilation
          repackaging
          prohibited without the prior written consent of VeriSign. You agree not to
          use electronic processes that are automated and high-volume to access or
          query the Whois database except as reasonably necessary to register
          domain names or modify existing registrations. VeriSign reserves the right
          to restrict your access to the Whois database in its sole discretion to ensure
          operational stability. VeriSign may restrict or terminate your access to the
          Whois database for failure to abide by these terms of use. VeriSign
          reserves the right to modify these terms at any time.
          The Registry database contains ONLY .COM
          Registrars.

          1 Reply Last reply Reply Quote 0
          • dafyreD
            dafyre
            last edited by

            Whois.exe outputs each line of text as an array element...

            $data[0]=""
            $data[1]="Whois v1.14 - Domain information lookup"
            .
            .
            .
            To output it to a file, you could do...

            $data -join ","|out-file -filepath "C:\temp\chip\whois_data.csv" -append

            computerchipC 1 Reply Last reply Reply Quote 0
            • computerchipC
              computerchip @dafyre
              last edited by

              @dafyre
              It already outputs everything to a file, that's the issue, it outputs everything, and I don't want anything after "DNSSEC"

              😃

              1 Reply Last reply Reply Quote 1
              • dafyreD
                dafyre
                last edited by

                @computerchip said in Powershell issues with splitting or trimming data in a $string:
                Change this: $data[0] | Out-File -filepath C:\temp\chip\whois_data.csv -append

                to

                $data=$data -join ","
                $intLastChar=$data.indexof("DNSSEC")+2
                $data=$data.substring(0,$intLastChar)
                

                That converts $data to a string (separated by comma), finds "DNSSEC" and adds two to it (to remove the leading comma), and then tosses out everything extra.

                1 Reply Last reply Reply Quote 1
                • computerchipC
                  computerchip
                  last edited by

                  @dafyre said in Powershell issues with splitting or trimming data in a $string:

                  @computerchip said in Powershell issues with splitting or trimming data in a $string:
                  Change this: $data[0] | Out-File -filepath C:\temp\chip\whois_data.csv -append

                  to

                  $data=$data -join ","
                  $intLastChar=$data.indexof("DNSSEC")+2
                  $data=$data.substring(0,$intLastChar)
                  

                  That converts $data to a string (separated by comma), finds "DNSSEC" and adds two to it (to remove the leading comma), and then tosses out everything extra.

                  I believe that's going to work, testing more now. Thanks!

                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    Last post