So what I need to do is match text until I hit a certain character, then stop. Right now I’m having a heck of a time getting that to work right and at this point I think I’m just confusing myself even more. The text I’m searching will look like this:
ServerA_logfile.log
ServerB_logfile.log
ServerC_logfile.log
What I need to do is just return the server name, and exclude everything after the underscore character.
Here’s my code:
Get-ChildItem \\fileshare\logs\ -Name -Filter *.log | foreach { [regex]::match($_ -replace "^_", "")}
What it returns is…. well, not helpful, but that’s as good as I can get.
What am I missing?
I know regex was requested, but it would be just as easy (maybe easier) to use the built in
splitcommand.Here is the code: