Howdy,
I have been trying to get a script working to check for a single service and I'm getting stuck. I have the script below which does get all services and I'm not far off, but I'm not sure how to query for the specific service name. I've read some posts where people use wmi-object and others where it is stated to use the built-in ps get-service, why is 1 option better or when is it correct to use 1 over the other? Also I want to output this as an excel report formatted "neatly" and "html" so I can compare this to provide as I was tasked with. Can anyone help, I've gathered this much so far from reading and testing. I'd also rather use a csv file for the input but got stuck there as well, so I went with a .txt file.
$ServerArray="c:\scripts\serverlist.txt"
$DefineSaveLocation=""
if ($DefineSaveLocation -eq "")
{$DefineSaveLocation="C:\Temp\ServiceandServiceAccounts\"}
$SavetoLocaPath = Test-Path $DefineSaveLocation
if ($SavetoLocaPath -eq $False)
{New-Item -ItemType directory -Path $DefineSaveLocation}
cd $DefineSaveLocation
Foreach ($Server in $ ServerArray )
{
Write-Host "Retrieving Servers for $Server "
Get-WmiObject win32_service -ComputerName $Server | select Name,
@{N="Startup Type";E={$_.StartMode}},
@{N="Service Account";E={$_.StartName}},
@{N="System Name";E={$_.Systemname}} | Sort-Object "Name" > ".\$Server -Services.txt"
}