Thursday, June 27, 2019

Find SCCM Distribution Points in Maintenance Mode in Powershell or SQL + Set Maintenance Mode


Since 1902 SCCM it is possible to set Distribution Point in Maintenance Mode https://docs.microsoft.com/en-us/sccm/core/servers/deploy/configure/install-and-configure-distribution-points#bkmk_maint


In "\Administration\Overview\Distribution Points" you can set  "Enable maintenance mode" / "Disable maintenance mode"



In log MICROSOFT CONFIGURATION MANAGER\LOGS\DISTMGR.LOG when you try to distribute a package to this DP you will find this message when a Distribution Point is in Maintenance mode:
 Skipping distribution point ["Display=\\SRVDP01.mydomain.net\"]MSWNET:["SMS_SITE=XXX"]\\SRVDP01.mydomain.net\ since its in maintenance mode



In Powershell to find Distribution Point in Maintenance mode us Get-CMDistributionPointInfo cmdlet

If you need to know all your Distribution Points in Maintenance Mode in Powershell as in console "\Administration\Overview\Distribution Points" you just need to use Get-CMDistributionPointInfo cmdlet


$allDPinMaintenanceMode = Get-CMDistributionPointInfo | Where-Object { $_.MaintenanceMode -eq 1 }
$allDPinMaintenanceMode | Select-Object Name,Main* | Format-List
Name                         :
SRVDP01.mydomain.net
MaintenanceMode              : 1
MaintenanceModeLastStartTime : 6/19/2019 6:48:00 AM


As you can see:
MaintenanceMode = 1 when Distribution Point Maintenance Mode is Enabled and MaintenanceMode = 0 when Distribution Point Maintenance Mode is Disabled (active Distribution Point)



















In SQL to find Distribution Point in Maintenance mode using View table


In log "MICROSOFT CONFIGURATION MANAGER\LOGS\SMSProv.log" you can find table used in console clicking in "\Administration\Overview\Distribution Points"
CExtProviderClassObject::DoCreateInstanceEnumAsync (SMS_Query)
Execute WQL  =SELECT * FROM SMS_DistributionPointInfo~ 
Execute SQL =select  all SMS_DistributionPointInfo.AddressScheduleEnabled
,SMS_DistributionPointInfo.BindExcept
,SMS_DistributionPointInfo.BindPolicy
,SMS_DistributionPointInfo.BitsEnabled
,SMS_DistributionPointInfo.CertificateType
,SMS_DistributionPointInfo.Communication
,SMS_DistributionPointInfo.Description
,SMS_DistributionPointInfo.DPFlags
,SMS_DistributionPointInfo.Drive
,SMS_DistributionPointInfo.EnableLEDBAT
,SMS_DistributionPointInfo.GroupCount
,SMS_DistributionPointInfo.HasRelationship
,SMS_DistributionPointInfo.HealthCheckEnabled
,SMS_DistributionPointInfo.HealthCheckPriority
,SMS_DistributionPointInfo.HealthCheckSchedule
,SMS_DistributionPointInfo.ID
,SMS_DistributionPointInfo.IdentityGUID
,SMS_DistributionPointInfo.InternetFacing
,SMS_DistributionPointInfo.IsActive
,SMS_DistributionPointInfo.IsMulticast
,SMS_DistributionPointInfo.IsPeerDP
,SMS_DistributionPointInfo.IsProtected
,SMS_DistributionPointInfo.IsPullDP
,SMS_DistributionPointInfo.IsPXE
,SMS_DistributionPointInfo.MaintenanceMode
,SMS_DistributionPointInfo.MaintenanceModeLastStartTime
,SMS_DistributionPointInfo.NALPath
,SMS_DistributionPointInfo.Name
,SMS_DistributionPointInfo.OperatingSystem
,SMS_DistributionPointInfo.PreStagingAllowed
,SMS_DistributionPointInfo.Priority
,SMS_DistributionPointInfo.PXEPassword
,SMS_DistributionPointInfo.RateLimitsEnabled
,SMS_DistributionPointInfo.Region
,SMS_DistributionPointInfo.ResourceType
,SMS_DistributionPointInfo.ResponseDelay
,SMS_DistributionPointInfo.SccmPXE
,SMS_DistributionPointInfo.ServerName
,SMS_DistributionPointInfo.ServiceType
,SMS_DistributionPointInfo.ShareName
,SMS_DistributionPointInfo.SiteCode
,SMS_DistributionPointInfo.SiteName
,SMS_DistributionPointInfo.SupportUnknownMachines
,SMS_DistributionPointInfo.TransferRate
,SMS_DistributionPointInfo.UdaSetting
,SMS_DistributionPointInfo.Version 
from v_DistributionPointInfo AS SMS_DistributionPointInfo  OPTION(USE HINT('FORCE_LEGACY_CARDINALITY_ESTIMATION'))~ 
CExtUserContext::LeaveThread : Releasing IWbemContextPtr=216121456

So to find DP in maintenance mode you just to use this SQL query:

SELECT * FROM v_DistributionPointInfo WHERE MaintenanceMode = '1'











In SQL to find Distribution Point in Maintenance mode using Table (just form information - do not use table directly - use View Table)

To find DP in maintenance mode you can also use this (not recommended) SQL query:

SELECT * FROM DistributionPoints WHERE MaintenanceMode = '1'












In Console, information about Maintenance Mode is in file
 C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\ConsoleRoot\SiteConfigurationNode.xml


In Powershell how to set  Maintenance Mode ?
To find that we can check SMS_DistributionPointInfo method

$smsdpinfo = [WmiClass]"\\SCCMSERVER.mydomain.net\root\SMS\Site_XXX:SMS_DistributionPointInfo"
($smsdpinfo | Get-Member -MemberType method).Definition
System.Management.ManagementBaseObject GetChainedPullDPs(System.String SourceDPNALPath)
System.Management.ManagementBaseObject ReassignDP(System.String NALPath, System.String SiteCode)
System.Management.ManagementBaseObject SetDPMaintenanceMode(System.String NALPath, System.UInt32 Mode)


with XXX = your Primary site Code
with SCCMSERVER.mydomain.net = your Primary SCCM Primary computername


And with some research we can find in Microsoft Documentation some information about SetDPMaintenanceMode
https://docs.microsoft.com/en-us/sccm/develop/reference/core/servers/configure/setdpmaintenancemode-method-in-class-sms-distributionpointinfo

So to set Maintenance Mode use (enabled) use:
$smsdpinfo = [WmiClass]"\\SCCMSERVER.mydomain.net\root\SMS\Site_XXX:SMS_DistributionPointInfo"
$smsdpinfo.SetDPMaintenanceMode('["Display=\\SRVDP01.mydomain.net\"]MSWNET:["SMS_SITE=XXX"]\\SRVDP01.mydomain.net\','1')
with XXX = your Primary site Code
with SCCMSERVER.mydomain.net = your Primary SCCM Primary computername
with SRVDP01.mydomain.net = DP to set in Maintenance Mode

So to remove Maintenance Mode use (diabled) use:
$smsdpinfo = [WmiClass]"\\SCCMSERVER.mydomain.net\root\SMS\Site_XXX:SMS_DistributionPointInfo"
$smsdpinfo.SetDPMaintenanceMode('["Display=\\SRVDP01.mydomain.net\"]MSWNET:["SMS_SITE=XXX"]\\SRVDP01.mydomain.net\','0')

When it is OK, ReturnValue = 0


Seems someone already create a simpliest powershell to set Maintenance Mode. So I will not reinvent wheel (...this time :-) ... ). So please go to
https://sccmf12twice.com/2019/06/set-cmdistributionpointmaintenancemode/
or directly to script
https://github.com/CodyMathis123/CM-Ramblings/blob/master/Set-CMDistributionPointMaintenanceMode.ps1