Windows Server - Remote WMI scripting problems

Asked By lyot
20-Aug-07 02:34 PM
I am trying to create a back-up of event logs on remote computers in my
domain. So far, it has worked fine with the exception that it can only
retrieve the event logs from the LOCAL computer that it was run-on. As far as
I know, there are no firewalls configured to block this network traffic. Can
someone please help?

today = FormatDateTime(Now, vbLongDate)

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("\TEXT FILE.txt", ForReading)

Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline

Set objFolder = objFSO.CreateFolder("NETWORK FOLDER" & strcomputer & "\" &
today & "\")

Set objWMIService = GetObject("winmgmts:" &

Set colLogFiles = objWMIService.ExecQuery ("SELECT * from
Win32_NTEventLogFile")

For Each objLogfile in colLogFiles
strBackupLog = objLogFile.BackupEventLog (objfolder & "\" &
objLogFile.LogFileName & ".evt")

Next

Loop

objTextFile.Close


Note: Anything with caps was an edit for this post.
SQL Server
(1)
Windows Server
(1)
Scripting.FileSystemObject
(1)
ObjTextFile.AtEndOfStream
(1)
ObjWMIService.ExecQuery
(1)
ObjFSO.OpenTextFile
(1)
Vista
(1)
ObjLogFile.BackupEventLog
(1)
  Richard Mueller [MVP] replied...
20-Aug-07 09:27 PM
For maximum compatibility with all clients I use:

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevelPkt,(Backup)}!\\"
_
& strComputer & "\root\cimv2")

In addition, both computers must have WMI, you need administrator privileges
on the remote computer (usually, this means you are a member of the "Domain
Admins" group, which is a member of the local Administrators group), DCOM
cannot be disabled, WMI cannot be blocked, and you need network
connectivity. Also, when reading from a text file it is easy to have blank
lines (if a carriage return is added at the end for example), so I code to
skip blank lines. Because so many things can go wrong, I like to trap the
possible error when attempting to connect with WMI. For example:
==============
Do Until objTextFile.AtEndOfStream
strComputer = Trim(objTextFile.Readline)
' Skip blank lines.
If (strComputer <> "") Then
Set objFolder = objFSO.CreateFolder("NETWORK FOLDER" & strcomputer &
' Trap possible errors.
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
&
& strComputer & "\root\cimv2")
If (Err.Number <> 0) Then
Call MsgBox("Failed to connect with WMI to " & strComputer _
& vbCrLf & "Error Number: " & Err.Number
& vbCrLf & "Description: " & Err.Description, _
vbOKOnly + vbCritical, "My Script Title")
' Restore normal error handling.
On Error GoTo 0
Else
' Restore normal error handling.
On Error GoTo 0
Set colLogFiles = objWMIService.ExecQuery ("SELECT * from
Win32_NTEventLogFile")

For Each objLogfile in colLogFiles
strBackupLog = objLogFile.BackupEventLog (objfolder & "\" &
objLogFile.LogFileName & ".evt")
Next
End If
Loop
===========
Also, WMI can become corrupt. Sometimes stopping and starting the WMI
service helps. Otherwise, see these links on troubleshooting WMI:

http://www.microsoft.com/technet/scriptcenter/topics/help/wmi.mspx

http://support.microsoft.com/kb/875605

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
  Richard Mueller [MVP] replied...
20-Aug-07 09:41 PM
Some time ago I researched how to connect to remote computers with WMI and
found the following:

1. You cannot connect to computers running XP Home.
2. An NT computer cannot connect to OS later than W2k.
3. A W2k3 computer cannot connect to Win9x.
4. To connect to W2k Server SP4 you must set impersonation level to
Impersonate.
5. W2k computers must have SP2 to connect to XP or above.
6. W2k3 can only connect to Win9x and NT if credentials supplied.
7. To connect to XP or W2k3 you must set authentication level to Pkt.

I determined this before Vista came out, so I need to add to the list.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
  lyot replied...
21-Aug-07 01:50 PM
Thank you for the help so far!
I tried adding in:
Set objWMIService = GetObject("winmgmts:" _ &
strComputer & "\root\cimv2")
For some reason it still failed to retrieve the event logs from remote
computers. Are there any other possible problems that could be causing this?
I'll try having another system administrator run it, in case they have
priviledges I'm not aware of, but is there any other potential cause to this
error?
  Richard Mueller [MVP] replied...
21-Aug-07 06:21 PM
There are many things that can go wrong with WMI. Check the troubleshooting
links I posted earlier.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
  JFor replied...
22-Aug-07 12:10 PM
It appears that the ".BackupEventLog" method does not like UNC or Network
shares, almost as if it exec's it with SYSTEM credentials.
  Richard Mueller [MVP] replied...
22-Aug-07 12:42 PM
I suspect a privilege issue. I know this is common when backing up SQL
Server databases, where the actual backup process uses the server computer
credentials. I don't know how BackupEventLog works, but either you, the
client, or the remote computer needs backup privileges. I don't know if this
link helps:

http://msdn2.microsoft.com/en-us/library/aa390430.aspx

The privilege is called wbemPrivilegeBackup. I can't find better
documentation.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
  Michael Harris \(MVP\) replied...
22-Aug-07 08:24 PM
Remote WMI automation uses account impersonation on the remote side.  The
impersonated account context on the remote side can access local (relative
to the remote WMI instance) file paths but not UNC paths (or any other kind
of remote resource) that requires a 2nd machine hop.

--
Michael Harris
MVP - Windows Server Admin Frameworks
Create New Account
help
AD replication Windows Server I have and exiting 2000 mixed mode domain just added a 2003 server into the mix and promoted it to DC The AD transfer happened but I am AD on the new DC. . . . . but havent observed the new user over in my 2000 server AD not sure if I am under the correct assumptions that I should see these old existing w2k DC I should see the AD correclty replicating between the 2 ? thanks Windows Server Active Directory Discussions DC (1) Administration (1) Eriecountygov (1) DNS (1) TCP (1) CN (1) LH (1) Server (1) Run diagnostics against your Active Directory domain. If you don't have the support tools installed, install them from your server install disk. d: \ support \ tools \ setup.exe Run dcdiag, netdiag and repadmin in verbose mode
Advice on best way to migrate to Server 2008 Windows Server This is what I have right now. . . . . 1. Windows Server 2000 sp4 acting as primary domain controller. 2. Windows Server 2000 sp4 acting as a backup domain controller. 3. Windows Server 2000 sp4 just a member server. 4. Windows Server 2003 WITH Exchange Server 2003
Error " The Target principal name is incorrect" Windows Server Hi All, I have big problem , becuase i miss take change the DC system day i don't reinstall the DC , becuase the DC is GC , Thanks, DC and DC2 : Windows 2003 Std R2 SP2 Windows 2000 Active Directory Discussions Windows Server 2003 R2 (1) Active Directory (1) MSSQLSvc (1) SupportedSASLMechanisms (1) SupportedLDAPPolicies (1) DHCPServer (1) IMAC the console tree, double-click Configuration [DomainControllerName], CN = Configuration, DC = [ForestRootDomain], CN = Services, and CN = Windows NT. 3. Right-click CN = Directory Service, and then click Properties. 4. In the Attribute www.blakjak.demon.co.uk / mul_crss.htm Hi All, Yes , because the Site A DC Server change the time to year 2002 (is my mistake ), now the site A server and
System Center Essentials 2007 - I can not install on Windows 2003 R2 (all updates) Windows Server I can not install System Center Essentials 2007 on Windows 2003 R2 32 bit with all updates. I try to use SQL 2005 Standard SP2 with Reporting Services. SQL and Reporting service is runing an domain administrator account. What to do. The system and domain is a fresh one runing and the VMWARE. PS: Here is a log: Report Server Database: SQL Server Instance: MSSQLSERVER Name: ReportServer The database will be accessed using the Service Context Virtual
AD state and dns windows2003r2x64 Windows Server My Company recently upgraded to server2003R2x64 with the help of a Microsoft Partner from Nt4 help. I have two main catogoty of issues I would like to resolve. thank you Windows Server DNS Discussions DomainDnsZones.ELLJHB.ELLIESHQ.LOCAL (1) DomainDnsZones.ELLIESHQ.LOCAL (1) ForestDnsZones.ELLIESHQ.LOCAL (1 D / E / s:HQDC1" Domain Controller Diagnosis Performing initial setup: * Connecting to directory service on server HQDC1. HQDC1.currentTime = 20080621173737.0Z HQDC1.highestCommittedUSN = 1417525 HQDC1.isSynchronized = 1 HQDC1.isGlobalCatalogReady = 1 * Collecting CN = Configuration, DC = ELLIESHQ, DC = LOCAL iSiteOptions = 0 dwTombstoneLifeTimeDays = 60 dwForestBehaviorVersion = 0 HomeServer = 0, HQDC1 SERVER: pServer[0].pszName = HQDC1 pServer[0].pszGuidDNSName = 6541722b-9298-4783-8f73-ac0eef5d620d._msdcs.ELLIESHQ.LOCAL DC = ELLIESHQ, DC = LOCAL pServer[0].ppszPartialNCs: ppszPartialNCs[0] = DC = ELLJHB, DC = ELLIESHQ, DC = LOCAL SERVER: pServer[1].pszName = HQDC2 pServer[1].pszGuidDNSName = b2aeeeca-c018-4ff1-af82-55a11417f52a._msdcs.ELLIESHQ.LOCAL DC = ELLIESHQ, DC = LOCAL pServer[1].ppszPartialNCs: ppszPartialNCs[0] = DC = ELLJHB, DC = ELLIESHQ, DC = LOCAL SERVER: pServer[2].pszName = JHBDC1 pServer[2].pszGuidDNSName = 5ae6c190-0a13-4a98-ade5-b99391085bf7._msdcs.ELLIESHQ.LOCAL