Solved

Ggroup policy to collect host name and mac address

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
In-place Upgrading Dirsync to Azure AD Connect
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 …
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 …

830 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