Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Curious question about -Split (powershell)

$
0
0

$String = @("asdf asdf asdf hijk hijk Database:001 asdf:45545 asdf asdf:4554 Database:101 hijk asdf "
"asdf asdf hijk Database:301 asdf asdf asdf asdf:4545 asdf asdf Database:011 hijk ")
Select-String -InputObject $String -Pattern 'Database:\d+' -AllMatches | %{$_.Matches} | %{$_.Value -split ':'}

I am a using above code as a part of a script..

I have seen in many  forums experts using %{$_.Matches} | %{$_.Value -split ':'} Select-String, however in above code I have noticed%{$_.Matches -split ':'}  also gives me the same result .

$_.Matches contain value as follows. I am not sure how split works on this object.. can someone explain?

Groups   : {Database:001}
Success  : True
Captures : {Database:001}
Index    : 25
Length   : 12
Value    : Database:001

Groups   : {Database:101}
Success  : True
Captures : {Database:101}
Index    : 64
Length   : 12
Value    : Database:101

Groups   : {Database:301}
Success  : True
Captures : {Database:301}
Index    : 103
Length   : 12
Value    : Database:301

Groups   : {Database:011}
Success  : True
Captures : {Database:011}
Index    : 151
Length   : 12
Value    : Database:011

Result

Database
001
Database
101
Database
301
Database
011


-Edatha-



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>