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?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 weeks, 5 days ago.

  • Author
    Posts
  • #180770

    Participant
    Topics: 43
    Replies: 78
    Points: 43
    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: 425
    Points: 691
    Helping Hand
    Rank: Major Contributor
    $TotalDevices = @('C90120','D90123','E90121','F90122')
    $TotalDevices | foreach {
        if ($_.EndsWith(0) -or $_.EndsWith(1)) {
            "here you go $_"
        } 
    }
    
  • #180779

    Participant
    Topics: 43
    Replies: 78
    Points: 43
    Rank: Member

    Well, FML!

    Thanks that worked.

You must be logged in to reply to this topic.