###################################################################################################


$ServiceNames = @(

   "Dhcp"

   "mpssvc"

   "Netlogon"

   "Spooler"

   "W32Time"

   "WinDefend"

   "WinRM"

   "wuauserv"

)

$Properties = @(

   "Name"

   "DisplayName"

   "MachineName"

   "ServiceName"

   "Status"

   "StartType"

)

$ServiceOutput = foreach ($ServiceName in $ServiceNames) {

       # OUTPUT GENERATE IN LIST VIEW

       Get-Service -Name $ServiceName | Select-Object $Properties

       # OUTPUT GENERATE IN TABLE VIEW # OUTPUT NOT IN PROPER FORMAT

       #Get-Service -Name $ServiceName | Select-Object $Properties | Format-Table -AutoSize

       # OUTPUT GENERATE IN TABLE VIEW # OUTPUT NOT IN PROPER FORMAT

       #Get-Service -Name $ServiceName | Format-Table -Property $Properties

}

$ServiceOutput | Format-Table -Property $Properties


###################################################################################################


$ServiceNames = @(

   "Dhcp"

   "mpssvc"

   "Netlogon"

   "Spooler"

   "W32Time"

   "WinDefend"

   "WinRM"

   "wuauserv"

)

$ServiceNames = Get-Service -Name $ServiceNames

$ServiceOutput = foreach ($ServiceName in $ServiceNames) {

   # PRINT EACH SERVICE'S DETAILS IN A CUSTOM FORMAT

   [PSCustomObject]@{

       Name        = $ServiceName.Name

       Status      = $ServiceName.Status

       DisplayName = $ServiceName.DisplayName

   }

}

$ServiceOutput | Format-Table -Property Name, Status, DisplayName