Trying to run Basic troubleshooting commands with error handling not sure how I could test the switches appropriately or if even on the right track

Records the results of running the commands and places a file in the c drive called profile corruption report.

Start-Transcript -Path "C:\ProfileCorruptionReport.txt"

# Run chkdsk /r /f with the yes option automatically chosen for you
Write-Output y | chkdsk C: /r /f
    # Run sfc /scannow sending the results to a file created in C:\SFC.txt. This is so I can later error handle certain outputs from SFC /scannow
    Start-Process -FilePath "C:\Windows\System32\sfc.exe" -ArgumentList '/scannow' -RedirectStandardOutput "C:\SFC.txt" -Wait 

    [String]$results = Get-Content('C:\SFC.txt')

    switch($results)
    {
    {$results -contains 'unable to fix some of them'}
    {Write-host 'unable to fix some of them'
    Dism  /Online /Cleanup-Image /StartComponentCleanup 
    Dism  /Online /Cleanup-Image /ScanHealth
    Dism  /Online /Cleanup-Image /RestoreHealth 
    Sfc /scannow
    }
    {$results -contains 'could not start the repair service'}
    {Write-host 'could not start the repair service'
    Dism  /Online /Cleanup-Image /StartComponentCleanup 
    Dism  /Online /Cleanup-Image /ScanHealth
    Dism  /Online /Cleanup-Image /RestoreHealth 
    Sfc /scannow
    }
    {$results -contains 'could not perform the requested operation'}
    {Write-host 'could not perform the requested operation'
    Dism  /Online /Cleanup-Image /StartComponentCleanup 
    Dism  /Online /Cleanup-Image /ScanHealth
    Dism  /Online /Cleanup-Image /RestoreHealth 
    Sfc /scannow
    }
    Default
    {Write-Host 'Default'
    Dism  /Online /Cleanup-Image /StartComponentCleanup 
    Dism  /Online /Cleanup-Image /ScanHealth
    Dism  /Online /Cleanup-Image /RestoreHealth 
    Sfc /scannow
    #shutdown /r
    }
    }```

Anthony,
Welcome to the forum. :wave:t3:

-contains does not work like you seem to think it does. It will check if a given element is in a given array of elements. And the given element has to be a perfect match. So for example it will find “Applejuice” in “Oragnejuice”, “Grapejuice”, “Applejuice”, “Strawbnerryjuice”. But it will NOT find Apple in that list. :wink:

A better approach might be to use -match in such a case.

Besides that …

Thanks for the heads up.