Question from configmgr forum :Query for disk space <500 MB on all servers last scan plus last 10 history scans.
History of disk space information is stored in v_HS_LOGICAL_DISK ,where as the current information is stored inv_GS_LOGICAL_DISK .
By Default,when you query v_HS_LOGICAL_DISK ,it gives you information with all the existing rows but how do i select the most recent 10 records for each computer ?
Below query gives you the information with most recent 10 records based on the timestamp for each computers.
with diskspace as (
SELECT SYS.Name AS [Server Name], CASE WHEN RSYS.Is_Virtual_Machine0 = 1 THEN 'Virtual Machine' ELSE 'Physical Machine' END AS [Hardware Type],
vHSLDISK.TimeStamp AS [Scaned Date], vHSLDISK.DeviceID0 AS [System Drive C:], vHSLDISK.FreeSpace0 AS [Free space (MB)]
, ROW_NUMBER() over (partition by SYS.Name order by vHSLDISK.TimeStamp desc) rno
FROM v_FullCollectionMembership AS SYS INNER JOIN
v_HS_LOGICAL_DISK AS vHSLDISK ON SYS.ResourceID = vHSLDISK.ResourceID INNER JOIN
v_R_System AS RSYS ON SYS.ResourceID = RSYS.ResourceID inner join
v_GS_LOGICAL_DISK AS LDISK ON SYS.ResourceID = LDISK.ResourceID
WHERE (vHSLDISK.DeviceID0 = 'c:') AND (SYS.CollectionID = 'P0100831') AND (vHSLDISK.FreeSpace0 <= 500)
select [Server Name],[Hardware Type],[Scaned Date],[System Drive C:],[Free space (MB)] from diskspace
Change the Collection ID ,Drive letter and disk Space value.
Reference TechNet Article : http://technet.microsoft.com/en-us/library/ms186734.aspx