script for getting 8 and 9 digit task sequence with multiple patterns

Welcome Forums General PowerShell Q&A script for getting 8 and 9 digit task sequence with multiple patterns

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

 
Participant
9 months ago.

  • Author
    Posts
  • #93870

    Participant
    Points: 0
    Rank: Member

    So I am trying to pull all 8 and 9 digit sequence from a text file. There is multiple patterns to these sequences, these could be xx-xxx-xxx, xx xxx xxx, xxxxxxxx, xxx-xx-xxxx, xxxxxxxxx, xxx xx xxxx. I came up with this but it is pulling more than just the numbers. Where am I making a mistake?

    $Num = @()

    $Num += Get-ChildItem -Path "$PSSCRIPTROOT\text.txt" |select-string " [0-9]{3}[-| ][0-9]{2}[-| ][0-9]{4}"
    $Num += Get-ChildItem -Path "$PSSCRIPTROOT\text.txt" |select-string " [0-9]{3}[-][0-9]{2}[-][0-9]{4}"
    $Num += Get-ChildItem -Path "$PSSCRIPTROOT\text.txt" |select-string " [0-9]{9}"

    $Num += Get-ChildItem -Path "$PSSCRIPTROOT\text.txt" |select-string " [0-9]{2}[-| ][0-9]{3}[-| ][0-9]{3}"
    $Num += Get-ChildItem -Path "$PSSCRIPTROOT\text.txt" |select-string " [0-9]{2}[-][0-9]{3}[-][0-9]{3}"
    $Num += Get-ChildItem -Path "$PSSCRIPTROOT\text.txt" |select-string " [0-9]{8}"

    ForEach ($Number in $Num){
    #$Number

    $Found = $Number.ToString().Split(":")
    $o = new-object PSObject
    $o | add-member NoteProperty "FoundOnLine" $Found[2]
    $o | add-member NoteProperty "Number" $Found[3]
    $o | add-member NoteProperty "Number2" $Found[4]
    $o | add-member NoteProperty "Number3" $Found[5]

    $o | export-csv "$PSscriptroot\FoundNumbers-$((get-date).ToString("M-dd-yyyy")).csv" -notypeinformation -Append -Force
    Write-Output $o

    }

  • #93877

    Participant
    Points: 165
    Helping Hand
    Rank: Participant

The topic ‘script for getting 8 and 9 digit task sequence with multiple patterns’ is closed to new replies.