It's just get-service converted to json with | ConvertTo-Json | Tee-Object services.txt
Somebody who wrote that line is using the resultant file in other scripts. I could possibly save the same as plain string but I can't think how it would help. Here I know as far as I can convert it back to json and address each line separately through the foreach loop. So maybe then one loop is sufficient like
foreach($name in $pre.name){
if(($name -eq $aft.name){
if(($name.status-eq $aft.status) -and ($name.starttype -eq $aft.starttype)){ then all good...
however how do I make sure I'm comparing the right service status and starttype bound to a given $aft.name not just some random one