/build/static/layout/Breadcrumb_cap_w.png

Miscellaneous Question


I need to have a custom inventory rule or a report that will return the size of the host file on all our computers. Any ideas? Thanks!

03/17/2016 707 views
I need to have a custom inventory rule or a report that will return the size of the host file on all our computers.  Any ideas?  Thanks!
Answer Summary:
0 Comments   [ + ] Show comments

Comments


Answer Chosen by the Author

0

Thanks for all the help from everyone!  I ended up using

    FileInfoReturn(c:\windows\system32\drivers\etc\hosts,size,NUMBER)

which worked perfectly.

Answered 03/21/2016 by: County of Culpeper
Yellow Belt

All Answers

1
shellcommandtextreturn(cmd /c wmic datafile where "name='c:\\Windows\\System32\\drivers\\etc\\hosts'" get name,size)
Answered 03/17/2016 by: SMal.tmcc
Red Belt

  • Nice, Steve. That cuts out much of my answer above. Much simpler, if he doesn't mind more info returning than just the file size.
    • he can drop "name" after the get if he wants also
1
here is another good one to monitor hosts file contents.  this will return anything not commented out

ShellCommandTextReturn(cmd /c echo off & for %g in (C:\Windows\System32\drivers\etc\hosts) do (findstr /b /v /c:"#" %g))
Answered 03/17/2016 by: SMal.tmcc
Red Belt

0
I just researched/played with this and came up with the following Powershell command which can be run:

(Get-ChildItem 'C:\Windows\System32\drivers\etc\hosts' -force | Select-Object -ExpandProperty Length | Measure-Object -Sum).sum|out-file C:\temp\test2.txt


Choose you own path and file name

This displays only the hidden file in C:\Windows\System32\drivers\etc, where hosts is. That outputted a file named test2.txt that gave me only the hosts file size in KB, nothing else in the text file

Then create a custom inventory rule:

ShellCommandTextReturn(cmd.exe /c type C:\temp\test2.txt)

That will create the Custom Inventory Field for each machine you ran the PowerShell script on. 

From there, I got the software ID of my Custom Inventory Field software entry and used this SQL for my report. Replace my 28696 with the ID of yours.

SELECT MACHINE.NAME AS SYSTEM_NAME, REPLACE((SELECT MACHINE_CUSTOM_INVENTORY.STR_FIELD_VALUE FROM MACHINE_CUSTOM_INVENTORY WHERE MACHINE_CUSTOM_INVENTORY.ID=MACHINE.ID AND MACHINE_CUSTOM_INVENTORY.SOFTWARE_ID=28696), '<br/>', '\r\n') AS MACHINE_CUSTOM_INVENTORY_0_2370 FROM MACHINE WHERE   (1  in (select 1 from MACHINE_CUSTOM_INVENTORY where MACHINE.ID = MACHINE_CUSTOM_INVENTORY.ID and MACHINE_CUSTOM_INVENTORY.SOFTWARE_ID = 28696 and MACHINE_CUSTOM_INVENTORY.STR_FIELD_VALUE LIKE '%b%'))  ORDER BY MACHINE.NAME asc
Answered 03/17/2016 by: rockhead44
Red Belt

0

To get the size of the hosts file


cmd

for %a in ("C:\Windows\System32\drivers\etc\hosts") do echo %~za

or

powershell

gci C:\Windows\System32\drivers\etc\hosts | select -expand length

To retrive the uncommented lines in the hosts file

findstr /b /v /c:"#" "C:\Windows\System32\drivers\etc\hosts"
Answered 03/19/2016 by: flip1001
Black Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ