Link to home
Create AccountLog in
Avatar of LONBUSS
LONBUSSFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBScript add info to a text file on a server

I'm just starting out to write VBScripts and I was wondering how easy it would be to write a script that get's info such as Computer name and IP and then adds them to a text file on a server.

Any help would be appreciated
Avatar of Isigow

with a winNT+ (2k/xp) client, batch is actually easier,

echo %username% %computername% %Logonserver% > \\server\share\file.txt

but since you want IP as well
Below is a easy (no file manipulation) way of running the same with vbscript, if you want to store it to a file just:
cscript myscript.vbs > \\server\share\file.txt

Set objShell = Wscript.CreateObject("Wscript.Shell")
Set WshProcessEnvironment = objShell.Environment("Process")
EnvLogonServer = WshProcessEnvironment("LogonServer")
EnvUsername = WshProcessEnvironment("username")
EnvComputerName = WshProcessEnvironment("computername")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
            EnvIP = EnvIP & " | "  &  IPConfig.IPAddress(i)
    End If

WScript.Echo EnvUserName & " | " & EnvComputerName & " | " & EnvLogonServer & " | " & EnvIP
Avatar of LONBUSS


Cheers Isigow,

But what if I don't want the output to be piped into txt file, but instead have the script ammend it to an existing txt file.  Is that harder to do?
Avatar of Isigow

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account