I need to keep the first 5 characters from data being pulled from a text file.
Data looks like this:
S1831KWT0081 S2004KWT0083 S2351KWT0085 S0054KWT0087
Results should looks like this:
S1831 S2004 S2351 S0054
I can get it working when setting the variable within PowerShell:
PS> $a = "S1831KWT0081"
PS> $a.Substring(0, $a.IndexOf('K'))
S1831
but I'm stuck when trying to pull from a text file.
$location = Get-Content "C:\location.txt" | ForEach-Object { $_.Substring(0, $_.IndexOf('K')) }