Partager via


Enable or Disable Incremental Collection Updates via PowerShell

Hi Gang.

Here is a couple of functions I’ve written to enable or disable Incremental Collection updates by Collection Name or Collection ID.

Enable via Collection ID

Enable-IncrementalUpdates -CollectionID PRI0000C

Enable via Collection Name

Enable-IncrementalUpdates –CollectionName “CU Deployment”

Disable via Collection ID

Disable-IncrementalUpdates -CollectionID PRI0000C

Disable via Collection Name

Disable-IncrementalUpdates –CollectionName “CU Deployment”

I’ve also added an optional parameter to specify the Server Name, so this can be run remotely by adding the SMS Provider name to your cmdlet

Enable-IncrementalUpdates -CollectionID PRI0000C –Server PRI

And of course it’s pipeline enabled

Import-CSV -Path .\collections.csv | % {Enable-IncrementalUpdates -CollectionName $_.Collection}

Here’s the code

Edit: Thanks to our commenter below, I’ve updated the script to perform the change depending on the membership schedule setting.

001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045 function Disable-IncrementalUpdates { [CmdletBinding(DefaultParameterSetName="CollectionID")] Param ( [Parameter(Mandatory=$true,ParameterSetName="collectionID", Position=0)] [String]$CollectionID, [Parameter(Mandatory=$true,ParameterSetName="collectionName", Position=0)] [String]$CollectionName, [Parameter(Mandatory=$false,ParameterSetName="collectionName", Position=1)] [Parameter(Mandatory=$false,ParameterSetName="collectionID", Position=1)] [String]$Server )if(!$server){ $server = '.'}$siteCode = @(Get-WmiObject -Namespace root\sms -Class SMS_ProviderLocation -ComputerName $server)[0].SiteCodegwmi sms_collection -ComputerName $server -Namespace root\sms\site_$siteCode -Filter "CollectionID = '$collectionID' or Name = '$collectionName'" | % {$collection = [wmi] $_.__Path If($collection.RefreshType -eq 4) {$collection.RefreshType = 1}If($collection.RefreshType -eq 6) {$Collection.RefreshType = 2}$collection.Put() | Out-Null} }function Enable-IncrementalUpdates { [CmdletBinding(DefaultParameterSetName="CollectionID")] Param    ( [Parameter(Mandatory=$true,ParameterSetName="collectionID", Position=0)] [String]$CollectionID, [Parameter(Mandatory=$true,ParameterSetName="collectionName", Position=0)] [String]$CollectionName, [Parameter(Mandatory=$false,ParameterSetName="collectionName", Position=1)] [Parameter(Mandatory=$false,ParameterSetName="collectionID", Position=1)] [String]$Server )if(!$server){ $server = '.'}$siteCode = @(Get-WmiObject -Namespace root\sms -Class SMS_ProviderLocation -ComputerName $server)[0].SiteCodegwmi sms_collection -ComputerName $server -Namespace root\sms\site_$siteCode -Filter "CollectionID = '$collectionID' or Name = '$collectionName'" | % {$collection = [wmi] $_.__Path If($collection.RefreshType -eq 1) {$collection.RefreshType = 4}If($collection.RefreshType -eq 2) {$Collection.RefreshType = 6}$collection.Put() | Out-Null } }

Happy POSHing!

Matt

Comments

  • Anonymous
    January 01, 2003
    Hey Ryan,
    Nope, wasn't intentionally left out... just missed the logic! Thanks, updated.
    Matt
  • Anonymous
    May 27, 2015
    There are two refresh types you missed.

    Refresh Type 1: Manual, No Incremental
    Refresh Type 2: Schedule, No Incremental
    Refresh Type 4: Manual, Incremental
    Refresh Type 6: Schedule Incremental

    In my scripts to change incremental updates, I first check to see what the current schedule is and change the setting based on whatever it's current set to. For instance, if the collection is set to Manual - Incremental, I change it to simply Manual. If the collection is set to Schedule - No Incremental, I'll switch it to Schedule - Incremental.

    I'm not sure if that was intentionally left out or not.