Solved

Exchange 2010, PowerShell

Posted on 2014-01-30
4
476 Views
Last Modified: 2014-01-31
I am trying to use this script here:

http://theboywonder.co.uk/2012/03/15/speeding-up-get-winevent-in-powershell-by-using-filterhashtable/

To do the following:

1) Scan all the exchange servers in the Organization and collect the events.

The commands work individually however I cannot figure out how to make the script connect to each of the Servers in the Exchange Organization. I tried using the command:

[PS] C:\>Get-WinEvent -FilterHashTable @{LogName='Application'; Level=1,2,3; StartTime="1/1/2014"} -ErrorAction Silently
Continue -Computer $Servers | Select-Object TimeCreated,LogName,ProviderName,Id,LevelDisplayName,Message
Get-WinEvent : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ComputerName'. Speci
fied method is not supported.
At line:1 char:130
+ Get-WinEvent -FilterHashTable @{LogName='Application'; Level=1,2,3; StartTime="1/1/2014"} -ErrorAction SilentlyContin
ue -Computer <<<<  $Servers | Select-Object TimeCreated,LogName,ProviderName,Id,LevelDisplayName,Message
    + CategoryInfo          : InvalidArgument: (:) [Get-WinEvent], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetWinEventCommand

AS you can see it did not work. I really am not a scripter so I am hoping you can help out here. I created my own server variable using the :

[PS] C:\>$Servers = get-content -Path c:\servers.txt

That worked however I still cannot use the command to get all the computers and then gather all the event logs.

Thanks,

Robert
0
Comment
Question by:castellansolutions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:footech
ID: 39823170
The simplest method is to process each server individually.
Try the following:
get-content -Path c:\servers.txt | ForEach `
{
    Get-WinEvent -FilterHashTable @{LogName='Application'; Level=1,2,3; StartTime="1/1/2014"} -ErrorAction SilentlyContinue -Computer $_ |
     Select-Object TimeCreated,LogName,ProviderName,Id,LevelDisplayName,Message
}

Open in new window

0
 
LVL 6

Author Comment

by:castellansolutions
ID: 39824533
This is great!! It worked however there is one last thing that I need to figure out, when I use the command it doesn't provide the server name where the events were generated from.

So in my lab I have 16 Exchange Servers.... How do I add the name ?
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 39824578
We can add that as a calculated property with Select-Object.
get-content -Path c:\servers.txt | ForEach `
{
    $server = $_
    Get-WinEvent -FilterHashTable @{LogName='Application'; Level=1,2,3; StartTime="1/1/2014"} -ErrorAction SilentlyContinue -Computer $_ |
     Select-Object @{n="Server";e={$server}},TimeCreated,LogName,ProviderName,Id,LevelDisplayName,Message
}

Open in new window

0
 
LVL 6

Author Comment

by:castellansolutions
ID: 39825647
Works like a charm!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
This video discusses moving either the default database or any database to a new volume.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question