0

I have a task which requires me to update a windows service. This service could be under different names - it asks for the install name upon installation of the service... but the Windows Event Logs are hard-coded to a specific name in C#:

if (!EventLog.SourceExists("MySuperSpecialEventLog"))
    EventLog.CreateEventSource("MySuperSpecialEventLog", "MyLog");

How can I find all servers with events logged to this custom log?

I've been toying with Powershell:

clear

import-module ActiveDirectory;
$servers = Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} -Property Name | Sort-Object name | Format-Table Name; #,OperatingSystem,OperatingSystemServicePack;
$servers

foreach($server in $servers){
   echo "Get-Eventlog -List -ComputerName $server"
}

This gives me a list of servers... then I'm trying to pull a list of Services ForEach server... then I can just filter...

But I can't seem to get the thing to click on all cylinders.

If powershell isn't the right tool - what else would work to find all servers with that specific EventLog?

  • your foreach should be foreach($server in $servers) – LotPings Dec 21 '16 at 20:43
  • yeah, that was a translation error... it's the stuff in the foreach that's got me confuzzled – WernerCD Dec 22 '16 at 0:44
  • What exactly are you looking for? You mentioned event logs (MyLog), and event log sources (MySuperSpecialEventLog), then you say you're trying to pull a list of services from each server. – Patrick Seymour Dec 22 '16 at 1:45
1
$source = "MySuperSpecialEventLog"
import-module ActiveDirectory
$servers = Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} | % { $_.Name }

$servers | % {
    Try {
        $eventlog = get-eventlog -Source $source -ComputerName $_ -newest 1 -ErrorAction Stop
        Write-Host $_ , ":", "has $source entries" 
    } Catch {
        Write-Host $_ , ":", $_.Exception.Message
    }
}

This would echo computer : has MySuperSpecialEventLog entries or computer : exceptionmessage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.