Solved

Exchange 2010, PowerShell

Posted on 2014-01-30
4
467 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a Distribution Group 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 >>…
In this video we show how to create an Address List 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 Organization >> Ad…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now