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:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

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

Please log in to comment

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
Please log in to comment
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

Please log in to comment
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
Tenth Degree Black Belt

Please log in to comment
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
Fourth Degree Green Belt

Please log in to comment
Answer this question or Comment on this question for clarity