Solved

Ggroup policy to collect host name and mac address

Posted on 2011-02-14
2
575 Views
Last Modified: 2012-05-11
i want to create group policy to collect host name and respective MAC address in CSV format.
Please help me to write script for the same.
0
Comment
Question by:aarun_tcs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 34894701
Do you have computers list? If so, you can use this

Create flat text file with computer names (one name per line, save as computers.txt on C-Drive) and run in command-line

for /f %i in (c:\computers.txt) do getmac /s %i /v /nh /fo csv >>c:\my.csv & echo %i >>c:\my.csv

or create log on script which will redirect output to network share where authenticated users or domain users will have modify permission

hostname >>\\UNCpath\mac.txt
getmac >>\\UNCpath\mac.txt

Regards,
Krzysztof
0
 
LVL 4

Accepted Solution

by:
loki_loki earned 500 total points
ID: 34905477
Somthing like this would do it.  You would have to add this as a login script on your GPO.  It updates one file, so make sure the location is accessible by all.  It will update daily but not overwrite any hostnames that have already been added.
Option Explicit
'On Error Resume Next

Dim strInfo, strFilename, LogFile, objFile, StrComp, strMAC, strReadFile
Dim fso, objWMIService, colItems, Network, strComputer, objItem

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

strComputer = "."


Set Network = WScript.CreateObject("Wscript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objItem in colItems
strMAC =  objItem.MACAddress
Next
 
StrComp = UCase(Network.ComputerName)

strInfo = StrComp & "," & strMAC

strFilename = "d:\info.csv" '"ENTER YOUR FILE NAME AND PATH HERE"

If Not fso.FileExists(strFilename) Then

 Set objFile = fso.CreateTextFile(strFilename)
 objFile.WriteLine strInfo
 objFile.Close

Else

 Set objFile = fso.OpenTextFile(strFilename, ForReading, True)
 strReadFile = objFile.ReadAll
 objFile.Close

 If InStr(strReadFile, StrComp) = 0 Then
   Set objFile = fso.OpenTextFile(strFilename, ForAppending, True)
   objFile.WriteLine strInfo
   objFile.Close
 End If
 
 End If

Open in new window

0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

627 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