browolf Posted June 6, 2007 Posted June 6, 2007 i made a bit in the staff login script that writes laptop mac/ethernet ads to a log file but because i've scraped it off the ipconfig cmd the string which has the mac ad in also contains a non alphanumeric character at the end that prevents me from creating a file with the mac as the name del \\backup\logs$\lapmacs\%computername%.log /q for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^| find "physical" /i ') do ( rem echo %computername% >> \\backup\logs$\lapmacs\%%a.log echo %%a >> \\backup\logs$\lapmacs\%computername%.log ) anyone know how to get rid of his chr? thx
Scruff Posted June 6, 2007 Posted June 6, 2007 this is psudo so probably not syntactically correct but i'd do something like %%a = left(%%a,len(%%a)-1) to remove the last 1 char edit: even messed it up in theory there , that looks better you probably don't have access to any of those functions though unfortunately
OutToLunch Posted June 6, 2007 Posted June 6, 2007 i'd hate trying to manipulate strings with FOR so I'd be tempted to make a copy of gawk available in the netlogon dir... then... ipconfig /all | find /i "physical" | gawk {"print \"set PCMAC=\" $12"} > tmp.bat call tmp.bat echo %COMPUTERNAME% > %PCMAC%.TXT del tmp.bat
plexer Posted June 6, 2007 Posted June 6, 2007 vbscript might be a better way then you can use string manipulation easily: http://www.dbforums.com/archive/index.php/t-885289.html http://www.microsoft.com/technet/scriptcenter/topics/msh/multivalued.mspx Ben
Scruff Posted June 6, 2007 Posted June 6, 2007 I just ran the script and the variable contains both leading and trailing blank characters, i'd be tempted to write a .vbs that returns a trim()'d version of the input and call it using ('cscript.exe //Nologo %variablehere%') you can then set a var using the output of the vbs I'll give it a go today and post if it works
browolf Posted June 6, 2007 Author Posted June 6, 2007 I just ran the script and the variable contains both leading and trailing blank characters, i'd be tempted to write a .vbs that returns a trim()'d version of the input and call it using ('cscript.exe //Nologo %variablehere%') you can then set a var using the output of the vbs I'll give it a go today and post if it works cool that seems to be the way forward.
ajbritton Posted June 6, 2007 Posted June 6, 2007 Assuming you are assigning IPs with DHCP, it should be possible to extract MACs from there. There is a freeware utility SpecOps GpUpdate which uses this technique to do WOL against computer accounts in AD.
Scruff Posted June 6, 2007 Posted June 6, 2007 OK, job done! what you need to do in your \\backup\logs$\lapmacs\ directory is create a file called enumerate.vbs (that's what i called it anyway) with the following in it Dim objFileSystem, objOutputFile Dim strOutputFile strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For each objItem in colItems 'Wscript.Echo objItem.MACAddress strOutputFile = "\\backup\logs$\lapmacs\" & Replace(objItem.MACAddress,":","-") & ".log" Set objFileSystem = CreateObject("Scripting.fileSystemObject") Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE) Set WshNetwork = WScript.CreateObject("WScript.Network") objOutputFile.WriteLine(WshNetwork.ComputerName) Set objFileSystem = Nothing Next then you need to add the following line into the code you pasted earlier: cscript.exe //NOLOGO \\backup\logs$\lapmacs\enumerate.vbs worked for me, hope it helps Edit: sorry i pasted that straight from getting it to work, i probably should have tidied it up a bit, but i'm sure you can see what it's doing and make it a bit nicer
browolf Posted June 8, 2007 Author Posted June 8, 2007 cool thx. however ive simplified it somewhat. strip.vbs Set objArgs = WScript.Arguments WScript.Echo trim(cstr(objArgs(0))) in login script bat rem log mac addresses del \\backup\logs$\lapmacs\%computername%.log /q >nul for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^| find "physical" /i ') do ( for /f %%b in ('cscript //nologo \\server1\netlogon\strip.vbs %%a') do ( echo %computername% > \\backup\logs$\lapmacs\%%b.log echo %%b >> \\backup\logs$\lapmacs\%computername%.log ) )
Scruff Posted June 8, 2007 Posted June 8, 2007 Hah, I had exactly the same thing earlier on in the day but I prefered for the vbs to pull the machine information as it's tidier than stripping strings from a cli output But whatever makes you happy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now