System Information VBScript

waltdeewaltdee Member Posts: 122
Hello guys,

I have a new project, i want to know the best way to pull system information from everyone in our domain using a vbs script. In this case i want to know how much RAM a number of users have and would like it to be saved in a spreadsheet on my PC.I know how to do it manually by using windows "system information" and remote in to a pc, but that would take a week to do manually. If anyone has any information, please let me know.

Thank you,
when one is the, the one will be the being of willing to be the one.

Comments

  • TechJunkyTechJunky Member Posts: 881
    Use VB and WMI to pull the information.

    Download the following tools to help you with coding.

    Scriptomatic2
    HTA_Helpomatic

    Those should give you the scripts your wanting.
  • [Deleted User][Deleted User] Senior Member Posts: 0 ■■■■□□□□□□
    You could also use PSTools from MS to get this type of information.
  • waltdeewaltdee Member Posts: 122
    TechJunky wrote: »
    Use VB and WMI to pull the information.

    Download the following tools to help you with coding.

    Scriptomatic2
    HTA_Helpomatic

    Those should give you the scripts your wanting.

    ok, i just installed WMITools, how do i use that?
    when one is the, the one will be the being of willing to be the one.
  • astorrsastorrs Member Posts: 3,139 ■■■■■■□□□□
    Have a look at some examples here for querying that information:

    Computer Hardware Scripts - VBScript samples
  • waltdeewaltdee Member Posts: 122
    astorrs wrote: »
    Have a look at some examples here for querying that information:

    Computer Hardware Scripts - VBScript samples

    Ok, thanks for the link, i was actually on the MS site checking those out. Now i still have a question, where in the script below, do i put in the name of the domain. Also where do i enter where i want the returned info saved. I know i know, i need to grab a vbscript book for dummies or something. But for now this info is very important. Thanks guys.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colSettings
    Wscript.Echo "OS Name: " & objOperatingSystem.Name
    Wscript.Echo "Version: " & objOperatingSystem.Version
    Wscript.Echo "Service Pack: " & _
    objOperatingSystem.ServicePackMajorVersion _
    & "." & objOperatingSystem.ServicePackMinorVersion
    Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer
    Wscript.Echo "Windows Directory: " & _
    objOperatingSystem.WindowsDirectory
    Wscript.Echo "Locale: " & objOperatingSystem.Locale
    Wscript.Echo "Available Physical Memory: " & _
    objOperatingSystem.FreePhysicalMemory
    Wscript.Echo "Total Virtual Memory: " & _
    objOperatingSystem.TotalVirtualMemorySize
    Wscript.Echo "Available Virtual Memory: " & _
    objOperatingSystem.FreeVirtualMemory
    Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
    Next
    Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
    For Each objComputer in colSettings
    Wscript.Echo "System Name: " & objComputer.Name
    Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer
    Wscript.Echo "System Model: " & objComputer.Model
    Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone
    Wscript.Echo "Total Physical Memory: " & _
    objComputer.TotalPhysicalMemory
    Next
    Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_Processor")
    For Each objProcessor in colSettings
    Wscript.Echo "System Type: " & objProcessor.Architecture
    Wscript.Echo "Processor: " & objProcessor.Description
    Next
    Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
    For Each objBIOS in colSettings
    Wscript.Echo "BIOS Version: " & objBIOS.Version
    Next
    when one is the, the one will be the being of willing to be the one.
  • astorrsastorrs Member Posts: 3,139 ■■■■■■□□□□
    None of these scripts are anywhere near complete for your needs, we were assuming you were going to take them forward. Since it sounds like you have little/no experience scripting, can you let me know *exactly* what information you want from the computers and I can probably write you a quick PowerShell script to do it in a few minutes.
  • phoeneousphoeneous Member Posts: 2,333 ■■■■■■■□□□
    waltdee wrote: »
    where in the script below, do i put in the name of the domain.

    If you have to ask, you probably shouldn't be running scripts. They can seriously mess things up.
  • PashPash Member Posts: 1,600 ■■■■■□□□□□
    You are welcome to use the Pshell script i did in this thread.

    It probably needs a little more work but it does the job. Let us know if you need anything else added.
    $ErrorActionPreference = "SilentlyContinue"
    
    #### Spreadsheet Location
    $strPath = "C:\Scripts\SERVERINFO\serverinfo.xls"
    
    $onerror = "SilentlyContinue"
    $a = New-Object -comobject Excel.Application
    $a.Visible = $True
    
    $b = $a.Workbooks.Add()
    $c = $b.Worksheets.Item(1)
    
    $c.Cells.Item(1,1) = "Machine Name"
    $c.Cells.Item(1,2) = "OS Running"
    $c.Cells.Item(1,3) = "Domain Role"
    $c.Cells.Item(1,4) = "Total Physical Memory"
    $c.Cells.Item(1,5) = "Total Free Physical Memory"
    $c.Cells.Item(1,6) = "Total Virtual Memory"
    $c.Cells.Item(1,7) = "Total Free Virtual Memory"
    $c.Cells.Item(1,[IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_cool.gif[/IMG] = "Last Boot Time"
    $c.Cells.Item(1,9) = "Bios Version"
    $c.Cells.Item(1,10) = "CPU Info"
    $c.Cells.Item(1,11) = "Disk Info"
    
    $d = $c.UsedRange
    $d.Interior.ColorIndex = 19
    $d.Font.ColorIndex = 11
    $d.Font.Bold = $True
    $d.EntireColumn.AutoFit()
    
    $intRow = 2
    $cred = Get-Credential
    ### For Use Later with Quest AD Cmdlets installed
    ### get-QADcomputer | format-table -hidetableheaders -property Name >> C:\Scripts\computers.txt
    $computers = Get-Content "C:\scripts\computers.txt"
    
    
    foreach ($computer in $computers)
    {
    #### Set Variables
    $user = $env:USERNAME
    
    #### Win32 class short name assignment - add -credential $cred where needed
    TRY {
    $OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer
    $Bios = Get-WmiObject -Class Win32_BIOS -ComputerName $computer 
    $CS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer 
    $CPU = Get-WmiObject -Class Win32_Processor -ComputerName $computer 
    $drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
    
    
    
    #### Set Variable information with short name
    $OSRunning = $OS.caption + " " + $OS.OSArchitecture + " SP " + $OS.ServicePackMajorVersion 
    $DomainRole = $CS.DomainRole
    $TotalAvailMemory = $OS.totalvisiblememorysize/1kb 
    $TotalVirtualMemory = $OS.totalvirtualmemorysize/1kb
    $TotalFreeMemory = $OS.FreePhysicalMemory/1kb
    $TotalFreeVirtualMemory = $OS.FreeVirtualMemory/1kb
    $TotalMem = "{0:N2}" -f $TotalAvailMemory
    $TotalVirt = "{0:N2}" -f $TotalVirtualMemory
    $FreeMem = "{0:N2}" -f $TotalFreeMemory
    $FreeVirtMem = "{0:N2}" -f $TotalFreeVirtualMemory
    $date = Get-Date 
    $uptime = $OS.ConvertToDateTime($OS.lastbootuptime)
    $BiosVersion = $Bios.Manufacturer + " " + $Bios.SMBIOSBIOSVERSION + " " + $Bios.ConvertToDateTime($Bios.Releasedate)
    $CPUInfo = $CPU.Name + " & has " + $CPU.NumberOfCores + " Cores & the FSB is " + $CPU.ExtClock + " Mhz"
    $CPULOAD = $CPU.LoadPercentage
    if (($DomainRole -eq "0") -or ($DomainRole -eq "1"))
    {
    $Role = "Work Station"
    }
    elseif (($DomainRole -eq "2") -or ($DomainRole -eq "3"))
    {
    $Role = "Member Server"
    }
    elseif (($DomainRole -eq "4") -or ($DomainRole -eq "5"))
    {
    $Role = "Domain Controller"
    }
    else
    {
    $Role = "Unknown"
    }
    }
    CATCH
    {
    $pcnotfound = "true"
    }
    #### Pump Data to Excel
    if ($pcnotfound -eq "true")
    {
    $c.Cells.Item($intRow, 1) = "PC Not Found"
    }
    else
    {
    $c.Cells.Item($intRow, 1) = $computer
    $c.Cells.Item($intRow, 2) = $OSRunning
    $c.Cells.Item($intRow, 3) = $Role
    $c.Cells.Item($intRow, 4) = "$TotalMem MB"
    $c.Cells.Item($intRow, 5) = "$FreeMem MB"
    $c.Cells.Item($intRow, 6) = "$TotalVirt MB"
    $c.Cells.Item($intRow, 7) = "$FreeVirtMem MB"
    $c.Cells.Item($intRow, [IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_cool.gif[/IMG] = $uptime
    $c.Cells.Item($intRow, 9) = $BiosVersion
    $c.Cells.Item($intRow, 10) = $CPUInfo
    
    $driveStr = ""
    foreach($drive in $drives)
    {
    $size1 = $drive.size / 1GB
    $size = "{0:N2}" -f $size1
    $free1 = $drive.freespace / 1GB
    $free = "{0:N2}" -f $free1
    $freea = $free1 / $size1 * 100
    $freeb = "{0:N2}" -f $freea
    $ID = $drive.DeviceID
    $driveStr += "$ID = Total Space: $size GB / Free Space: $free GB / Free (Percent): $freeb % ` " 
    }
    $c.Cells.Item($intRow, 11) = $driveStr
    }
    
    $d.EntireColumn.AutoFit()
    
    $intRow = $intRow + 1
    $pcnotfound = "false"
    }
    
    IF(Test-Path $strPath)
    {
    Remove-Item $strPath
    $a.ActiveWorkbook.SaveAs($strPath)
    }
    ELSE
    {
    $a.ActiveWorkbook.SaveAs($strPath)
    }
    
    

    Because your question directly relates to pulling pc names from AD bind and then using that info, powershell Quest AD cmdlets are very handy. Can be found here

    Personally I always add the Add-Snapin for the active server roles to the administrator profile and then it loads the cmdlets in every shell i use (the install instructions are in the pdf document on the downloads page).

    If your intentions are to use vbscript solely then yes in all honesty you could do with a scripting book for vb. Take no notice of the people who say you shouldnt be scripting if you dont get xxx, the whole point of doing this stuff is to learn, but make sure you understand why. I think the main reason a lot of admins are going with powershell now is because of the shell, and honestly v 2.0 with remoting and little thing's like TRY, CATCH, FINALLY is fantastic (anyone learning or using C# day to day will appreciate that stuff). Don't be afraid to experiment!

    Pash
    DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
  • phoeneousphoeneous Member Posts: 2,333 ■■■■■■■□□□
    Pash wrote: »
    Don't be afraid to experiment!

    Pash

    Agreed, but in a test environment first.
  • crrussell3crrussell3 Member Posts: 561
    xmalachi wrote: »
    You could also use PSTools from MS to get this type of information.

    +1
    Use PSINFO as a computer startup script and have it pipe the results to a txt file on a share.
    MCTS: Windows Vista, Configuration
    MCTS: Windows WS08 Active Directory, Configuration
  • forkvoidforkvoid Member Posts: 317
    Could also use Spiceworks, or WMI Asset Logger. No scripting necessary, and does the job and more.
    The beginning of knowledge is understanding how little you actually know.
  • PashPash Member Posts: 1,600 ■■■■■□□□□□
    forkvoid wrote: »
    Could also use Spiceworks, or WMI Asset Logger. No scripting necessary, and does the job and more.

    Spiceworks is ok, but you add lot's of things in and it does start to feel bloated.

    The whole point of scripting is you have little overhead and scalable results.
    DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
  • mikedisd2mikedisd2 Member Posts: 1,096 ■■■■■□□□□□
    Pash wrote: »
    You are welcome to use the Pshell script i did in this thread.

    It probably needs a little more work but it does the job. Let us know if you need anything else added.
    Pash

    You wrote that script? Last week I was feeling clever because I discovered how to use "$cred = Get-Credential".
  • PashPash Member Posts: 1,600 ■■■■■□□□□□
    mikedisd2 wrote: »
    You wrote that script? Last week I was feeling clever because I discovered how to use "$cred = Get-Credential".

    I am slowly getting there with powershell I think, I am much better than I was a year ago.

    Also had help in understanding things from various regulars and ex-regulars to the site.

    Keep at it and just think on what useful things you can do with a simple script.

    Pash
    DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
Sign In or Register to comment.