Some month ago I should create a powershell script. I don't know if last powershell SCCM now add this functionnality but below I share you how you can do it:
Since Windows PowerShell changes in Cumulative Update 4 for System Center 2012 R2 Configuration Manager we can use New-CMEmbeddedObjectInstance
New-CMEmbeddedObjectInstance
For advanced use cases in which you have to directly manipulate result objects from the SMS Provider or from object queries. Creates a new embedded object of an ad hoc class. Notice that for "SMS_EmbeddedProperty" or "SMS_EmbeddedPropertyList" types, there is New-CMEmbeddedProperty and New-CMEmbeddedPropertyList.
Example
$prop = New-CMEmbeddedObjectInstance -ClassName "SMS_EmbeddedProperty"
So to enable on-demand use this scriplet
$DistPoint = "dp_computername" # dp computername
$SiteCode = "ABC" # site code
$DP = Get-CMDistributionPoint -SiteSystemServerName "$($DistPoint)*" -SiteCode $SiteCode
$props = $dp.EmbeddedProperties
if ($DP.EmbeddedProperties.ContainsKey("DistributeOnDemand") ) {
$props["DistributeOnDemand"].Value = 1
} else {
$embeddedProperty = New-CMEmbeddedProperty -PropertyName "DistributeOnDemand" -Value 1
$props["DistributeOnDemand"] = $embeddedProperty
}
$DP.EmbeddedProperties = $props
$DP.put()
else you want use "old school" queries use tricks as explained in https://david-obrien.net/2013/01/how-to-configure-configmgr-distribution-point/
$DistPoint = "dp_computername" # dp computername
$SiteCode = "ABC" # site code
$CM = "myprimary.mydomain.net" # primary server name
$Query = "SELECT * FROM SMS_SCI_SysResUse WHERE NALPath Like '%$DistPoint%' AND RoleName='SMS Distribution Point' "
$DPSiteRes = Get-WmiObject -Namespace "root\SMS\Site_$SiteCode" -Query $Query -ComputerName $CM
$props = $DPSiteRes.Props
$prop = $props | where {$_.PropertyName -eq "DistributeOnDemand"}
if ($prop) {
$prop.Value = 1
} else {
$embeddedproperty_class = [wmiclass]""
$embeddedproperty_class.psbase.Path = "\\$($CM)\ROOT\SMS\Site_$($SiteCode):SMS_EmbeddedProperty"
$embeddedproperty = $embeddedproperty_class.createInstance()
$embeddedproperty.PropertyName = "DistributeOnDemand"
$embeddedproperty.Value = 1
$props += [System.Management.ManagementBaseObject]$embeddedproperty
}
$DPSiteRes.props = $props
$DPSiteRes.put()
No comments:
Post a Comment