Solved

Ggroup policy to collect host name and mac address

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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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