Copy and use
Script Library
74 scripts for SCCM and Windows admins. Each page has the code, a copy button and the steps to run it.
SCCM SQL queries
Check BitLocker protection status for each computerSQL query for the Configuration Manager database that shows if BitLocker protection is on or off for the drives of each computer.
Check distribution point content status for a packageSQL query for the Configuration Manager database that shows the content status of one package on every distribution point.
Check software update compliance for one updateSQL query for the Configuration Manager database that lists each computer that still needs one update, found by its KB article number.
Count computers by manufacturer and modelSQL query for the Configuration Manager database that counts computers for each manufacturer and model.
Count Configuration Manager client versions in your environmentSQL query for the Configuration Manager database that counts how many computers run each client version.
Count installs per application and versionSQL query for the Configuration Manager database that counts how many computers have each application and version installed.
Count missing required updates per computerSQL query for the Configuration Manager database that counts the required software updates each computer is missing, worst first.
Count Windows 10 and Windows 11 computers by buildSQL query for the Configuration Manager database that counts Windows 10 and Windows 11 computers for each edition and build number.
Find computers that are pending a restartSQL query for the Configuration Manager database that lists computers waiting for a restart and shows the reason for each one.
Find computers that have not rebooted in 14 daysSQL query for the Configuration Manager database that lists computers with a last boot time older than a number of days you set.
Find computers with low free space on the C: driveSQL query for the Configuration Manager database that lists computers with less free space on C: than the number of GB you set.
Find computers with no hardware inventory in 30 daysSQL query for the Configuration Manager database that lists clients with a last hardware scan older than a number of days, or no scan at all.
Find duplicate computer names and duplicate serial numbersTwo SQL queries for the Configuration Manager database that find computer names with more than one record and serial numbers used by more than one record.
List all collections a computer belongs toSQL query for the Configuration Manager database that lists every collection one computer is a member of, with collection ID and comment.
List all computers with a named application installedSQL query for the Configuration Manager database that lists every computer with an application name you search for, with version and publisher.
List computers in an Active Directory OUSQL query for the Configuration Manager database that lists every computer in an Active Directory OU and in the OUs below it.
List computers in an IP subnetSQL query for the Configuration Manager database that lists every computer in one IP subnet, or counts computers per subnet.
List inactive or unhealthy Configuration Manager clientsSQL query for the Configuration Manager database that lists clients that are inactive or failed the client health check, with last contact dates.
List installed RAM for each computerSQL query for the Configuration Manager database that lists the installed memory in GB for each computer, with a filter for low memory.
List the members of a collectionSQL query for the Configuration Manager database that lists every member of a collection you name, with domain, site code and client state.
List the serial number and BIOS version of each computerSQL query for the Configuration Manager database that lists serial number, BIOS version and BIOS date for every computer, with model.
Show task sequence step results for one computerSQL query for the Configuration Manager database that lists every task sequence step a computer ran, with exit code and time.
Show the deployment status summary for an application or packageSQL query for the Configuration Manager database that shows success, in progress, error and unknown counts for each deployment of an application or package.
Show the primary user and last logged on user of each computerSQL query for the Configuration Manager database that lists the primary user, the last logged on user and the inventory user for each computer.
SCCM PowerShell
Change the SCCM client cache sizeRead and set the size of the SCCM client cache in MB through the client COM object, without opening the control panel.
Check if a computer has a pending rebootCheck the SCCM client and the Windows registry keys to find out whether a computer waits for a restart.
Check that WMI and the root\ccm namespace are healthyTest the WMI service, the WMI repository, a basic WMI query and the root\ccm namespace of the SCCM client in one run.
Clear the SCCM client cache the safe wayRemove content from the ccmcache folder through the SCCM client COM object, so the client keeps a correct record of what is in its cache.
Detection script template for an SCCM applicationA PowerShell detection method for an SCCM application that checks a file version and a registry value and follows the output and exit code rule.
Get the SCCM client version, site code and management pointRead the SCCM client version, the assigned site code and the current management point from a local or remote computer with CIM.
Install all available software updates on an SCCM client nowStart the install of every missing software update that is deployed to an SCCM client, the same as Install All in Software Center.
List pending and failed software updates on an SCCM clientShow the software updates that an SCCM client still has to install, with the state and the error code of each one.
List Software Center applications and their install stateList the applications that an SCCM client shows in Software Center, with version, install state and error code.
Read the last error lines from an SCCM client logPull the most recent error lines out of an SCCM client log such as AppEnforce.log, on a local or remote computer, as a clean table.
Restart the SCCM client service on a remote computerRestart the CcmExec service (SMS Agent Host) on one or more remote computers through PowerShell remoting and report the new status.
Run an SCCM client action on every computer in a text fileTrigger one SCCM client action on a list of computers from a text file and get a result line per computer, ready for a CSV file.
Trigger SCCM client actions with PowerShellStart machine policy, hardware inventory, update scan or app evaluation on an SCCM client from PowerShell, without opening the control panel.
WQL collection queries
Find all laptops by chassis typeA WQL collection query that returns laptops and other portable computers, based on the chassis type from hardware inventory.
Find all virtual machinesA WQL collection query that returns every virtual machine, using the IsVirtualMachine flag that the SCCM client reports.
Find all Windows 11 computersA WQL collection query that returns every computer running Windows 11, based on the operating system name from hardware inventory.
Find all workstations and leave out serversA WQL collection query that returns every Windows workstation and leaves out servers. One word changes it into an all servers query.
Find computers by IP subnetA WQL collection query that returns the computers on one IP subnet, for site based deployments and office collections.
Find computers by manufacturer and modelA WQL collection query that returns computers from one manufacturer and one model, for driver, BIOS and firmware deployments.
Find computers by name prefix or naming patternA WQL collection query that returns computers whose name starts with a prefix or matches a naming pattern, such as LAB-%.
Find computers in an Active Directory OUA WQL collection query that returns the computers in one Active Directory organizational unit, including the OUs below it.
Find computers in an Active Directory security groupA WQL collection query that returns the computers that are members of one Active Directory security group.
Find computers with a named application installedA WQL collection query that returns computers with a named application installed. It checks both the 32-bit and the 64-bit program lists.
Find computers with an old SCCM client versionA WQL collection query that returns computers whose SCCM client version is lower than the version you name.
Find computers with less than 10 GB free disk spaceA WQL collection query that returns computers whose C: drive has less free space than the number of megabytes you set.
Find computers with no hardware inventory in 30 daysA WQL collection query that returns computers whose last hardware inventory scan is more than 30 days old.
Find computers with no SCCM client installedA WQL collection query that returns discovered computers that have no SCCM client, so you can see what still needs an install.
Find computers without a named applicationA WQL collection query that returns computers that do not have a named application. It uses the "not in" subselect pattern.
Find Windows 10 computers by build numberA WQL collection query that returns Windows 10 computers on one build number, such as 19045 for version 22H2.
Windows admin PowerShell
Check certificate expiry dates in the local machine storeList the certificates in the local machine store that have expired or will expire within a number of days, with the days left for each.
Check free disk space on a list of computersReport the size, free space and free percent of every fixed drive on a list of computers, and flag the drives that run low.
Export the members of the local Administrators groupList the members of the local Administrators group on one or more computers and save them to a CSV file for an access review.
Find an uninstall string and remove an MSI silentlySearch the registry for an application, show its uninstall string, and remove an MSI product silently with msiexec and a log file.
Find and delete files older than N daysDelete files older than a number of days from a folder, with -WhatIf support and a guard against drive roots and system folders.
Find the largest files and folders on a driveList the biggest files and the biggest top-level folders under a path, so you can see what fills a drive without extra tools.
Find who is logged on to a remote computerList the users with a desktop session on a local or remote computer, including remote desktop sessions, with the session start time.
Get failed logons or application errors from the last 24 hoursPull failed logon events (ID 4625) or application error events from the event log for the last 24 hours, as a short readable table.
Get last boot time and uptime for a list of computersShow when each computer in a list last started and how many days it has been up, with a clear error line for the ones that do not answer.
Get serial number, model and BIOS versionRead the serial number, manufacturer, model and BIOS version and date from one or more computers, for warranty checks and firmware planning.
List installed software from the registry (32-bit and 64-bit)List installed programs from both uninstall keys in the registry. It is fast and it avoids the slow Win32_Product class.
Stop or restart a service on many computersStop, start or restart one Windows service on a list of computers through PowerShell remoting, with the status of each computer in the result.
Test if a TCP port is open on a list of serversCheck one or more TCP ports on a list of servers with a short timeout. It is much faster than Test-NetConnection on hosts that do not answer.
Command line
Install the SCCM client with ccmsetup.exe and the most used switchesA ccmsetup.exe command reference for a manual SCCM client install, with the most used switches and properties explained.
Mirror a content source folder with robocopy, logging and retriesA robocopy command that mirrors a content source folder to a share, with a test run, a log file and limited retries.
Open the SCCM client control panel and Software Center from the command lineCommands that open the Configuration Manager control panel applet and Software Center, including a direct jump to one Software Center tab.
Repair the WMI repository the careful wayThe winmgmt commands to check and repair a WMI repository in the safe order, and why /resetrepository is the last resort.
Reset Windows Update componentsThe commands to reset Windows Update on a client. Stop the services, rename SoftwareDistribution and catroot2, then start the services.
Run DISM and SFC health repair in the right orderThe DISM and SFC commands to repair Windows system files, in the right order, with the log files to read after.
Run msiexec for a silent install, a silent uninstall and a verbose logThe msiexec command lines for a silent MSI install, a silent uninstall, a repair and a verbose log file for troubleshooting.
Uninstall the SCCM client cleanly and check that it is goneThe ccmsetup /uninstall command for a clean SCCM client removal, plus the checks that prove the client is gone.
No script matches that. Try one word, like "reboot" or "disk".
Bigger scripts
The full SCCM report queries have their own articles.