Powershell Query

Associate
Joined
12 Jun 2005
Posts
836
Location
Newcastle
Can anyone shed light on the following, running the below command to try and start scripting a tool to check our servers

get-wmiobject win32_ntlogevent -filter ("Type='Error'")

Or also tried the following as a test

get-wmiobject win32_ntlogevent -filter ("EventCode='1030'") >> test.txt

And the output is



Category : 0
Category String :
Event Code :
Event Identifier :
Type Event :
Insertion Strings :
Log File :
Message : Windows cannot query for the list of Group Policy objects. Check the event log for possible message
s previously logged by the policy engine that describes the reason for this.

Record Number :
Source Name :
Time Generated :
Time Written :
Type : Error
User Name :

Basically need to know why the fields are blank as this needs to be populated, and the version of PowerShell is 1 and this cannot be upgraded.

Thanks in advance :)
 
Associate
OP
Joined
12 Jun 2005
Posts
836
Location
Newcastle
Hi J,

Is the output from get-wmiobject win32_ntlogevent -filter ("Type='Error'") also blank? Which server OS are you querying against?

Running it on 2003 R2 and that command returns results, but the same fields are blank.

get-wmiobject -class win32_NTlogevent -computer .| select -first 10 | out-file “C:\temp\class1.txt”



Have look at this, you may be able to develop this further.

Running that (had to take out the out-file bit, think thats PS2?) gets 10 records but the same fields are blank, example below

Category : 0
Category String :
Event Code :
Event Identifier :
Type Event :
Insertion Strings :
Log File :
Message : Security policy in the Group policy objects has been applied successfully.

Record Number :
Source Name :
Time Generated :
Time Written :
Type : Information
User Name :
 
Associate
Joined
31 May 2005
Posts
2,057
Location
Alfreton,Derbyshire
$filename = "FileName{0:ddMMyyyy-HHmm}" -f (Get-Date)
$comps = Import-Csv -Path C:\CompNames.txt -Delimiter ","
foreach($item in $comps){
Get-EventLog -ComputerName $item.ComputerName -LogName System -Newest 20 -EntryType Error | Export-Csv -Path "C:\$filename.csv" -Force
}

Example of CompName

Server1,TS
Server2,SQL

Any help?
 
Associate
OP
Joined
12 Jun 2005
Posts
836
Location
Newcastle
$filename = "FileName{0:ddMMyyyy-HHmm}" -f (Get-Date)
$comps = Import-Csv -Path C:\CompNames.txt -Delimiter ","
foreach($item in $comps){
Get-EventLog -ComputerName $item.ComputerName -LogName System -Newest 20 -EntryType Error | Export-Csv -Path "C:\$filename.csv" -Force
}

Example of CompName

Server1,TS
Server2,SQL

Any help?

The -ComputerName item does not work on PowerShell V1. This is the pain of not being able to install PowerShell 2 or PowerShell add-ins.
 
Back
Top Bottom