Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save file based on PC name

Status
Not open for further replies.

QuarkIT

IS-IT--Management
Jan 11, 2005
34
US
I have a script that locates the PC's security log and exports it to a file on the server.

The only problem with the script is that I do this for about 30 computers. Currently we do the audit manually and place the output file in a folder corresponding to the PC's name

IE: Workstation 13's security log goes to \\server\security audit\workstation 13

What I'd like to do is automate this script so that it will save to the correct folder based on the PC's name.
 
Need to see the script you are using to be of help. There are several way to do what you want.

Here is a snippet from Marc's most excelent Domain logon script that gets some basic server and user information and stores them into variables you can use to name the file you need.

Hope this helps.

Code:
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' URL   : [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
'          Maps and disconnects drives and printers

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UserString = WSHNetwork.UserName

'Bind to the user object to get user name and check 
'for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
strUser = objUser.Name

'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName

Thanks

John Fuhrman
Titan Global Services
 
Here's the script

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Security'")
For Each objLogfile in colLogFiles
OutputFile = "\\server3\Data2\Projects\Data\PERSONAL\%systemname%\" & "Security "
OutputFile = OutputFile & month(now) & "-" & day(now) & "-" & year(now)
OutputFile = OutputFile & ".evt"
errBackupLog = objLogFile.BackupEventLog(OutputFile)
If errBackupLog = 0 Or errBackupLog = 183 Then
objLogFile.ClearEventLog()
Else
Wscript.Echo "The Security event log could not be backed up."
End If
Next

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This was what I was given. I've used Mark's scripts in the past, I just don't know how to go about capturing the PC name.
 
Have you tried to replace \%systemname%\ with \%computername%\ ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Whoops. The %systemname% area in the script was me testing it with another set of code.

The actual path was specific to a folder, neither systemname nor computername work.
 
PC name can be retrieved like this

Code:
Dim objNetwork, strComputer

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
WScript.Echo strComputer
or

Code:
Dim objShell, strComputer

Set objShell = CreateObject("WScript.Shell")
strComputer = objShell.ExpandEnvironmentStrings("%computername%")
WScript.Echo strComputer

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Durr, I read that a few times and looked over it entirely (silly me)

Here's what the final script looks like, the path is subject to change, but it does what I need

Dim objNetwork, strComputer

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
& strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Security'")
For Each objLogfile in colLogFiles
OutputFile = "\\server3\Data2\Projects\Data\PERSONAL\" &strComputer& "\Security "
OutputFile = OutputFile & month(now) & "-" & day(now) & "-" & year(now)
OutputFile = OutputFile & ".evt"
errBackupLog = objLogFile.BackupEventLog(OutputFile)
If errBackupLog = 0 Or errBackupLog = 183 Then
objLogFile.ClearEventLog()
Else
Wscript.Echo "The Security event log could not be backed up."
End If
Next




Thanks for the help everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top