Hello All,
I have a text file containing the following:
*---- A D G R O U P S ----*
AD Group001
AD Group002
AD Group003
AD Group004
AD Group005
AD Group006
AD Group007
AD Group008
AD Group009
AD Group010
*---- S C R I P T N O T E S ----*
IT Service Desk ticket number:
TEST000006
Account AD groups were copied from:
IleneDover
I’m trying to create a script that will just display the listed AD groups. The script kinda works, and displays the following:
*---- A D G R O U P S ----*
AD Group001
AD Group002
AD Group003
AD Group004
AD Group005
AD Group006
AD Group007
AD Group008
AD Group009
AD Group010
But I just want the AD groups and not the heading “---- AD GROUPS ----” to be displayed. I think this should be a simple fix, and I usually can muddle my way through these things but my “muddle isn’t muddling” today. Any help would be greatly appreciated. Thanks!
Here’s my code:
$filePath = "C:\_ScriptOutput\TEST-ADGroupList.txt"
$startString = "*---- A D G R O U P S ----*"
$stopString = "*---- S C R I P T N O T E S ----*"
$reading = $false
Get-Content -Path $filePath | ForEach-Object {
$line = $_
# Exit if the stop condition is met
if ($line -eq $stopString)
{
break
}
if ($line -like "*$startString*") {
$reading = $true
}
# Start listing line items when the start string is found.
if ($reading) {
Write-Host $line
}
}