Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

VB Script: create txt file with DateStamp and IP Adress

VBS script :

Hello experts,

I am looking for a vbscript procedure in order to

1-Create a file with the following name  Creatation_date_IP_adress of the machine

The following format should be used:DDMMMYYYY_HHMMSS__IP_adress
IP adress refers to the machinemachine in which it is launched.

Here is the reference function

' Build string of current date time (DDMMYYYY_HHMMSS)
Function TimeStamp(dtmDateTime)
   TimeStamp = Year(dtmDateTime) & Right("0" & Month(dtmDateTime), 2) & Right("0" & Day(dtmDateTime), 2) & "_" & Right("0" & Hour(dtmDateTime), 2) & Right("0" & Minute(dtmDateTime), 2) & Right("0" & Second(dtmDateTime), 2)
End Function

Open in new window


'Retrieve IP adress
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IP Addresses: " & Join( objItem.IPAddress, "," )
        End If
    End If
Next

WScript.Echo strIP

Open in new window

2-File should contains the following

“[DDMMYYYY_HHMMSS]


3-The procedure should should contains the following param:

Sub(outputFolder) outputFolder refers to the folder in which should be generated the file.

If you have question don't hesitate to contact me.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Thank you for this proposal. Instead of using the IP (numerical number) do you think it is possible to readapat the function to have the name of the machine?
Set objWMIService = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem" )
For Each objItem in colItems
    strComputerName = objItem.Name
    WScript.Echo "Computer Name: " & strComputerName
Next

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It works! Thank you very much for your help!
Avatar of Bill Prew
Bill Prew

Welcome.

~bp