Function Get-SiteCode
{
$wqlQuery = 'SELECT * FROM SMS_ProviderLocation'
$a = Get-WmiObject -Query $wqlQuery -Namespace 'root\sms' -ComputerName $SMSProvider
$a | ForEach-Object -Process {
if($_.ProviderForLocalSite)
{
$script:SiteCode = $_.SiteCode
}
}
return $SiteCode
}
Function Convert-NormalDateToConfigMgrDate
{
[CmdletBinding()]
param (
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]$starttime
)
return [System.Management.ManagementDateTimeconverter]::ToDMTFDateTime($starttime)
}
Function create-ScheduleToken
{
$SMS_ST_RecurInterval = 'SMS_ST_RecurInterval'
$class_SMS_ST_RecurInterval = [wmiclass]''
$class_SMS_ST_RecurInterval.psbase.Path = "\\$($SMSProvider)\ROOT\SMS\Site_$($SiteCode):$($SMS_ST_RecurInterval)"
$script:scheduleToken = $class_SMS_ST_RecurInterval.CreateInstance()
if($scheduleToken)
{
$scheduleToken.DayDuration = 0
$scheduleToken.DaySpan = 0
$scheduleToken.HourDuration = 0
$scheduleToken.HourSpan = 2
$scheduleToken.IsGMT = $false
$scheduleToken.MinuteDuration = 0
$scheduleToken.MinuteSpan = 0
$scheduleToken.StartTime = (Convert-NormalDateToConfigMgrDate $starttime)
}
}
[datetime]$starttime = [datetime]::Today
$SMSProvider = 'BRGSCCM01v'
$SiteCode = Get-SiteCode
create-ScheduleToken
#$Keyword = '%' + $Keyword.Replace(' ','%') + '%'
$Collections = Get-WmiObject -Class SMS_Collection -Namespace root\sms\site_$SiteCode -Filter "CollectionType = '2' AND Name like '%Update%'"
foreach ($Collection in $Collections)
{
try
{
$Coll = Get-WmiObject -Class SMS_Collection -Namespace root\sms\site_$SiteCode -ComputerName $SMSProvider -Filter "CollectionID ='$($Collection.CollectionID)'"
$Coll = [wmi]$Coll.__PATH
$Coll.RefreshSchedule = $scheduleToken
$null = $Coll.put()
Write-Verbose -Message "Successfully edited Collection $($Coll.Name)."
}
catch
{
Write-Verbose -Message "$($Coll.Name) could not be edited."
}
}