Hi,
If no output is wanted you can simply remove the ”Write-Host“ lines.
$Servers = Get-Content -Path "C:\Users\CPCWM\Desktop\Services Status Pre patch checking\Serverlist.txt"
$Services = Get-Content -Path "C:\Users\CPCWM\Desktop\Services Status Pre patch checking\Services.txt"
$Date = Get-Date -Format "dd-mm-yy hh:mm"
$Servreportpre = $null
$Servreportpre = @()
$x=0
foreach($Server in $Servers)
{
$x=$x+1
Write-Host "Service Status StartType for Server $x :$Server" -ForegroundColor Yellow
foreach($Service in $Services)
{
$Status = Get-WmiObject Win32_Service -ComputerName $Servers | ?{$_.Name -eq $Service} | Select-Object -ExpandProperty "State"
$StartType = Get-WmiObject Win32_Service -ComputerName $Servers | ?{$_.Name -eq $Service} | Select-Object -ExpandProperty "StartMode"
if($Status -like "Running")
{
$Servreportpre += $Server | Select @{n='ServerName';e={$_}}, @{n='ServiceName';e={"$Service"}}, @{n='Status';e={"$Status"}}, @{n='StartType';e={"$StartType"}}
}
elseif($Status -like "Stopped")
{
$Servreportpre += $Server | Select @{n='ServerName';e={$_}}, @{n='ServiceName';e={"$Service"}}, @{n='Status';e={"$Status"}}, @{n='StartType';e={"$StartType"}}
}
}
}
$Pdate = Get-Date -Format "dd-mm-yy hh:mm"
$Servreportpre | Export-Csv -Path "C:\Users\CPCWM\Desktop\Services Status Pre patch checking\Service Status Pre Check Report.csv" -NoTypeInformation
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.