Ok, so in a perfect SCCM world you would never have any SCCM client installation failures and this post would be totally unnecessary. But in the real world, you are very likely to have a number of systems that fail to install the SCCM client and the reasons can be many.
To identify such systems, it can be helpful to create collections for some of the common client installation failure codes so you can easily see and report on which type of installation failures you are experiencing and the number of systems affected.
To identify the installation failure error codes you have in your environment for Windows systems, run the following SQL query against the SCCM database:
select
Count(cdr.Name) as 'Count',
cdr.CP_LastInstallationError as 'Last Installation Error Code'
from v_CombinedDeviceResources cdr
where
cdr.CP_LastInstallationError is not null
and cdr.IsClient = 0
and cdr.DeviceOS like '%Windows%'
group by cdr.CP_LastInstallationError
order by 'Count' desc

Next simply create a collection for each error code using the following WQL query, changing the LastInstallationError value to the relevant error code:
select
SYS.ResourceID,
SYS.ResourceType,
SYS.Name,
SYS.SMSUniqueIdentifier,
SYS.ResourceDomainORWorkgroup,
SYS.Client
from SMS_R_System as SYS
Inner Join SMS_CM_RES_COLL_SMS00001 as COL on SYS.ResourceID = COL.ResourceID
Where COL.LastInstallationError = 53
And (SYS.Client = 0 Or SYS.Client is null)
Error codes are all fine and dandy, but unless you have an error code database in your head you’ll want to translate those codes to friendly descriptions. To do that, I use a PowerShell function I created that pulls the description from the SrsResources.dll which you can find in any SCCM console installation. There’s more than one way to translate error codes though – see my blog post here. Better yet, create yourself an error code SQL database which you can join to in your SQL queries and is super useful for reporting purposes – see my post here.
Anyway, once you’ve translated the error codes, you can name your collections with them for easy reference:

Now comes the hard part – figuring out how to fix those errors and working through all the affected systems 😬
Hi
The WOL query is throwing an error saying a Syntax error
Just tested it a couple of times in different sites and is working well for me.