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
Windows 2000
Last Comment
Isigow
8/22/2022 - Mon
Isigow
with a winNT+ (2k/xp) client, batch is actually easier,
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)
Next
End If
Next
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("Wscr
Set WshProcessEnvironment = objShell.Environment("Proc
EnvLogonServer = WshProcessEnvironment("Log
EnvUsername = WshProcessEnvironment("use
EnvComputerName = WshProcessEnvironment("com
Set objWMIService = GetObject("winmgmts:{imper
Set IPConfigSet = objWMIService.ExecQuery("S
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress)
For i=LBound(IPConfig.IPAddres
EnvIP = EnvIP & " | " & IPConfig.IPAddress(i)
Next
End If
Next
WScript.Echo EnvUserName & " | " & EnvComputerName & " | " & EnvLogonServer & " | " & EnvIP