Solved

Ggroup policy to collect host name and mac address

Posted on 2011-02-14
2
570 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
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

Join & Write a Comment

Starting in Windows Server 2008, Microsoft introduced the Group Policy Central Store. This automatically replicating location allows IT administrators to have the latest and greatest Group Policy (GP) configuration settings available. Let’s expl…
Resolve DNS query failed errors for Exchange
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

760 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

21 Experts available now in Live!

Get 1:1 Help Now