- [Info]
- 3= data1
- 2= data2
- 4 =data3
- [info2]
- 1 =data1
- 2 = data2
- 3 =data3
SLS context
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: SLS context
I am sorry I am revisiting this but where did you get $found from? Also how does this get everything after info2. I am sorry if I am not understanding the concept here.
Re: SLS context
Ok lets start from the begaining here because I am missing something. I do a sls and I want everything after the string I am selecting. Normally I would use context but the list may be big and I don't want to guess. I am trying to understand where the variable $found comes from? The code below gets me the [infor2].
- line = sls -path .\Settings.txt -Pattern '[Info2]'
- foreach ($element in $line.line)
- {
- if ($element -eq '[Info2]') { $element }
Re: SLS context
Ok what you explicitly gave doesn't work. Or I misunderstanding here. Please see the below.
OUTPUT:
- $line = sls -path .\Settings.txt -Pattern '[info2]'
- foreach ($element in $line.line)
- {
- if ($element -match '[info2]') { $found = $true }
- if ($found) { $element }
- }
Re: SLS context
No it is outputting everything.
instead of just outputting everything under [info2]
- [Info]
- 3= data1
- 2= data2
- 4 =data3
- [info2]
- 1 =data1
- 2 = data2
- 3 =data3
- 1 = data1
- 2 = data2
- 3 = data3
Re: SLS context
The following code will work better for what you are trying to do:
https://gallery.technet.microsoft.com/E ... 67?redir=0
https://gallery.technet.microsoft.com/E ... 67?redir=0
Re: SLS context
I see what you meant by explicit. I just couldn’t see it. Still working on my understanding with certain concept when comes to scripting. Well if anyone has the same issue and can understand here is the script in full.
$line = sls -path .\Settings.txt -Pattern '[info2]'
$checkForline = $false
$line | %{
if ($checkForline) { $_.line }
if ($_.line -eq '[info2]')
{
$checkForline = $true
}
}
$_
$line = sls -path .\Settings.txt -Pattern '[info2]'
$checkForline = $false
$line | %{
if ($checkForline) { $_.line }
if ($_.line -eq '[info2]')
{
$checkForline = $true
}
}
$_