I'm assuming that you're only interested in the services that are declared in array. If so, try this, you just need to edit the last line to output an XML file:
trap [Exception]
{
Write-Error -Message ("TRAPPED: " + $_.Exception.Message)
}
$logfile = "D:\citrixout.log"
Clear-Host
$computers = Get-Content -Path "D:\Computers.txt"
$start = $true
$outputServices = @()
$serviceNames = @(
'CitrixXTEServer',
'CitrixWMIService',
'Citrix 64-bit Virtual Memory Optimization',
'Citrix Encryption Service',
'Citrix Encryption Service',
'Citrix SMA Service',
'Citrix Virtual Memory Optimization',
'CitrixHealthMon',
'IMAService'
)
foreach ($computer in $computers)
{
Write-Host "Checking $computer" -ForegroundColor Black -BackgroundColor Blue | Out-File -FilePath $logfile -Append -NoClobber
$allServices = Get-Service -ComputerName $computer
foreach ($service in $allServices)
{
foreach ($serviceName in $serviceNames)
{
if ($service.Name -eq $serviceName)
{
Write-Host $testing "$serviceName is present on $computer." -ForegroundColor Green
if ($service.State -eq "Running")
{
Write-Host "$serviceName is running on $computer" -ForegroundColor Green
}
else
{
Write-Host "$serviceName is not running on $computer" -ForegroundColor Yellow
if ($start -eq $true)
{
Write-Host "Attempting to start $serviceName on $computer." -ForegroundColor Red
Start-Service -Name $serviceName
$s = Get-Service -Name $serviceName
Write-Host '$($s.Name) is "$($s.State)" on $computer.' -ForegroundColor Cyan
}
}
$outputServices += Get-Service -Name $serviceName
}
}
}
}
$outputServices | Out-GridView
(ConvertTo-XML -InputObject $outputServices -As Document).Save("Your_File_Name.xml")