Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ggroup policy to collect host name and mac address

Posted on 2011-02-14
2
Medium Priority
?
578 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 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Here's a look at newsworthy articles and community happenings during the last month.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

715 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