summaryrefslogtreecommitdiff
path: root/scripts/setup/windows/uninst.ps1
blob: d5c898d8ee77568eb5cac00f490fe24a147388ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$profileContent = Get-Content $PROFILE -ErrorAction SilentlyContinue
if ($profileContent) {
    $startMarker = "# JustEnoughVCS - Begin #"
    $endMarker = "# JustEnoughVCS - End #"
    $newContent = @()
    $insideBlock = $false
    $foundStart = $false

    foreach ($line in $profileContent) {
        if ($line.Trim() -eq $startMarker) {
            $insideBlock = $true
            $foundStart = $true
            continue
        }
        if ($line.Trim() -eq $endMarker) {
            $insideBlock = $false
            continue
        }
        if (-not $insideBlock) {
            $newContent += $line
        }
    }

    if ($foundStart -and $insideBlock) {
        $newContent = @()
        $insideBlock = $false
        foreach ($line in $profileContent) {
            if ($line.Trim() -eq $startMarker) {
                $insideBlock = $true
                continue
            }
            if (-not $insideBlock) {
                $newContent += $line
            }
        }
    }

    $newContent | Set-Content $PROFILE
}