Right now I'm reading a File from line to line, and searching a string in it.
If I found a right Line, I just needed 1 word from the String, so I could delete everything but that string. Now I have multiple Strings int the Line which are separated by Spaces. The Problem is that the Line has a lot of spaces at the start so I can't split the sentence or remove all spaces because then the multiple words would merge to one. Here's an example:
Some Lines in the File for example:
Network 1:
protocols ping ssh icmp
names PC001 PC002 PC003
Network 2:
protocols ping ssh icmp
...
Code:
Get-Content $file | ForEach-Object{
$line = $_
if($line -like "*protocols*"){
$Protocols = $line.Replace("protocol ", "")
$Protocols = $Protocol.Replace(" ", "")
}
}
I know it isn't the best but I'm open to improvements.