So i have folder with several files:
$files = @(Get-ChildItem "myPath")
I can see via the debugger that $files contains several items and i want to take the first:
$files[0] = "123_this.is.string"
And i want to split in by '_' and take 123
$splitted = $files[0] -split "_"
So here i can see that $splitted is empty.
Any suggestions why this strange behavior ?
Nameproperty value to split. Your$file[0]should contain an object with a bunch of properties, and you can't split objects. Try$files[0].Name -Split '_'.$files[0] -split "_"and$files[0].Name -split "_"should give the same result.