Albert Widjaja
asked on
Need help in modifying Powershell script to list service with specific pattern and its status ?
Hi All,
Can anyone here please assist me in modifying the Powershell script below so that it can go through the list of servers within the specific OU and then list all of the service with the name that has the keyword " *Application 1*" along with the server name, service name, service running status, Startup Status and the service account running ?
Because there are about 3-4 services per server with the keyword " *Application 1*" like:
Application 1 Watcher
Application 1 Server
Application 1 Updater
Any help would be greatly appreciated.
Thanks in advance,
Can anyone here please assist me in modifying the Powershell script below so that it can go through the list of servers within the specific OU and then list all of the service with the name that has the keyword " *Application 1*" along with the server name, service name, service running status, Startup Status and the service account running ?
Because there are about 3-4 services per server with the keyword " *Application 1*" like:
Application 1 Watcher
Application 1 Server
Application 1 Updater
$path = "C:\TEMP\"
$serverlist = Get-ADComputer -Properties Name -Filter {Enabled -eq $True -and OperatingSystem -like "*Windows Server*"} -SearchBase "OU=Servers,DC=domain,DC=com" |
Where-Object {$_.DistinguishedName -notlike "*OU=Decommissioned Servers,OU=Servers,DC=domain,DC=com"} |
Where-Object {Test-Connection $_.Name -Count 1 -Quiet}
$servicename = "Application 1"
foreach ($server in $serverlist){
$servicetorestart = Get-Service -name -Include $servicename -ComputerName $server.Name -ErrorAction SilentlyContinue
......
# what else to fill in here
......
} | Export-Csv -Path $path -NoClobber -NoTypeInformation -UseCulture
Any help would be greatly appreciated.
Thanks in advance,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks for the suggestion and the codes people,
However in some of the Windows Server 2012 R2 VMs, I get:
is it because the service is non existent or is it because of the Symantec Firewall ?
However in some of the Windows Server 2012 R2 VMs, I get:
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
is it because the service is non existent or is it because of the Symantec Firewall ?
That's probably because of the Firewall then. The error means that the WMI query failed, so it didn't even get access to query the services.
ASKER
Thanks All for the suggestion and the solution.
OBDA solution works great.
Mahesh, your script is partially works:
result filename is ServiceStatus_DD11YYYY_093 8.csv and the content is not showing when modifying the line
$services = Get-WmiObject Win32_Service -ComputerName $($server.DNSHostName) -ErrorAction SilentlyContinue | ?{$_.DisplayName -like "HP Insight"}
OBDA solution works great.
Mahesh, your script is partially works:
result filename is ServiceStatus_DD11YYYY_093
$services = Get-WmiObject Win32_Service -ComputerName $($server.DNSHostName) -ErrorAction SilentlyContinue | ?{$_.DisplayName -like "HP Insight"}
you need to use
?{$_.DisplayName -match "HP Insight"}
?{$_.DisplayName -match "HP Insight"}
ASKER
I have modified it into:
Open in new window
But somehow there is no error and the .CSV result is empty 0 KB file size ?