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!
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!
0 Comments
[ + ] Show comments
Answers (5)
Answer Summary:
Please log in to answer
Posted by:
SMal.tmcc
8 years ago
shellcommandtextreturn(cmd /c wmic datafile where "name='c:\\Windows\\System32\\drivers\\etc\\hosts'" get name,size)
Comments:
-
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. - rockhead44 8 years ago
-
he can drop "name" after the get if he wants also - SMal.tmcc 8 years ago
Posted by:
SMal.tmcc
8 years ago
Posted by:
rockhead44
8 years ago
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
Posted by:
flip1001
8 years ago
Posted by:
County of Culpeper
8 years ago