Popular Posts

Monday, July 31, 2017

SCCM 2007 - SQL views / sample reports / WQL queries


SQL views

Among the various views available in SCCM 2007 database, there are two identical(yet different) types of views, HS and GS.
Here GS refers to Current data and HS refers to Historical data.
Knowing this comes handy when choosing the correct view to be queried on a report.



SQL reports


Get update lists per software update KB (all variants)



select DisplayName, CI_ID from fn_ListAuthListCIs(1033) AS sul where sul.CI_ID in (
select rel.FromCIID from v_CIRelation
AS rel where rel.ToCIID IN (select CI_ID from fn_ListUpdateCIs(1033) AS su where su.ArticleID='4054522'))





Get domain of all clients



select Name0,Domain0 from v_GS_COMPUTER_SYSTEM




Last patched date for all servers



select * from (
select PS.LastStatusTime, PS.LastStateName, SYS.Name0, OS.LastBootUpTime0,
ROW_NUMBER() OVER(PARTITION BY SYS.Name0 ORDER BY PS.LastStatusTime DESC) rn
from v_gs_patchstatusEx PS
inner join v_R_System SYS ON PS.ResourceID = SYS.ResourceID
inner join v_GS_OPERATING_SYSTEM OS ON SYS.ResourceID = OS.ResourceID
where LastStateName = 'Install Verified' AND (PS.LastStatusTime < Getdate())
AND PS.isActive = '1') a where rn=1 ORDER BY LastBootUpTime0 DESC





Collection membership for certain client



select v_FullCollectionMembership.CollectionID As 'Collection ID', v_Collection.Name As 'Collection Name', v_R_System.Name0 As 'Machine Name' from v_FullCollectionMembership
JOIN v_R_System on v_FullCollectionMembership.ResourceID = v_R_System.ResourceID
JOIN v_Collection on v_FullCollectionMembership.CollectionID = v_Collection.CollectionID
Where v_R_System.Name0= '<hostname>'




Update lists applicable for a certain collection (ID)


select distinct UL.Title, case when ULL.Status='1' then 'Not Required'
when ULL.Status='2' then 'Required' when ULL.Status='3' then 'Installed'
end as 'Install Status'
FROM v_UpdateListStatus_Live ULL
INNER JOIN v_AuthListInfo UL ON ULL.CI_ID=UL.CI_ID
INNER JOIN v_R_System SYST ON SYST.ResourceID=ULL.ResourceID
INNER JOIN v_FullCollectionMembership CM on SYST.ResourceID=CM.ResourceID
where CM.CollectionID = '<collection ID>' AND UL.Title NOT LIKE '%SQL%'
AND UL.Title NOT LIKE '%CSA%' AND UL.Title LIKE '%(APPROVED)%'
AND ULL.Status = '2'



WQL queries

Client Systems installed within the last 48 hours

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner  join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceId = SMS_R_System.ResourceId   inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where (DateDiff(hh, SMS_G_System_OPERATING_SYSTEM.InstallDate, GetDate()) < 48) and SMS_G_System_SYSTEM.SystemRole = "Server" and SMS_G_System_OPERATING_SYSTEM.InstallDate <= GetDate()



Wednesday, December 14, 2016

PowerShell System Variables / "Cannot override variable" error

I was working on a PowerShell script at work where I came across this weird issue. I kept getting "Cannot override variable" error when I try to run my script. After hours of trials and some help of StackOverflow, i learnt that one of the variables I had used is actually a system variable that cannot be overridden. In Fact, I had used $error as a variable to store an error message, a string, which was causing my script to fail.

To list down PowerShell system variables, use Get-Childitem env:

$Error is not really listed here, unless there is actual error created. But if you do a write-host or return from command prompt and type $erro or less, a Tab key input will complete the command. And ofcouse you can write to cmd or return the value, which in most cases is a null.

Wednesday, January 15, 2014

WD My Book Live

Recently my office supervisor bought this so called 'Personal cloud storage' from Western Digital(WD) called MY BOOK LIVE. This device can be used in a home network, where users who are in the same network as the WD drive can connect using the desktop application provided by WD. To connect to this drive from anywhere else, the user can use the wd2go.com website or mobile applications.

The funny thing is that you cannot share files that are created from MS office applications such as Word/Excel when you access them over the internet through wd2go.com.  
The problem seems to be that Microsoft has added a second layer of security for its files created from the office suite of newer versions such as MS office 2007 and onwards. 

It's quite shameful that WD still haven't been able to find a solution for this problem, but still sell these products as 'personal cloud storage'. However thanks to few tech blokes, a workaround can be found in several blogs and discussions which uses SSH to connect to the drive over the internet..

http://community.wd.com/t5/My-Book-Live/WD2go-webDAV-and-MS-Office-2013/m-p/513536#M16552  

http://mybookworld.wikidot.com/forum/t-593394/streaming-ms-office-files-over-remote-mybooklive#post-1631975

I hope this post helps those who face the problem.