How to get all computer names that end in a zero?

Welcome Forums General PowerShell Q&A How to get all computer names that end in a zero?

Viewing 2 reply threads
  • Author
    Posts
    • #180770
      Participant
      Topics: 44
      Replies: 79
      Points: 57
      Rank: Member

      I need to get a list of computers that just have either a zero or a 1 at the end of its name.

      The computer names are alphanumeric.

      For instance, let's say that I have a list and I have a variable that contains the list of computer names that I will call $TotalDevices.

      Here is what I did and it is working for most systems that have names like C90123, it's fine, but with names like Test-Win10-X64, it does not seem to work so well because it breaks up the name and puts portions of it on separate lines possible because of the hyphens, but I am not certain:

      [regex]::Matches($TotalDevices, '\D+\d+\').value

    • #180776
      Participant
      Topics: 9
      Replies: 427
      Points: 712
      Helping Hand
      Rank: Major Contributor
      $TotalDevices = @('C90120','D90123','E90121','F90122')
      $TotalDevices | foreach {
          if ($_.EndsWith(0) -or $_.EndsWith(1)) {
              "here you go $_"
          } 
      }
      
    • #180779
      Participant
      Topics: 44
      Replies: 79
      Points: 57
      Rank: Member

      Well, FML!

      Thanks that worked.

Viewing 2 reply threads
  • The topic ‘How to get all computer names that end in a zero?’ is closed to new replies.