繁琐的部分是转换 ActivationTime,由于某种原因,它显示为字符串,而不是根据文档的预期日期时间:
https://msdn.microsoft.com/en-us/library/ee268286%28v=bts.10%29。 aspx?f=255&MSPPError=-2147217396
试一试,以下内容将删除所有超过 5 天的暂停消息:
# Now minus 5 days
$OlderThan = (get-date).AddDays(-5)
Write-Host "Will look for suspended message(s) older than:"$OlderThan
# Convert from date to string
$OlderThan = $OlderThan.ToString("yyyyMMddHHmmss")
# Get all suspended messages older than value in $OlderThan
$SuspendedMsgs = Get-WmiObject MSBTS_ServiceInstance -namespace 'root\MicrosoftBizTalkServer' | Where-object {$_.ServiceStatus -eq 4 -or $_.ServiceStatus -eq 32 -and $_.ActivationTime -lt $OlderThan}
# If any suspended messages matching critiera found
If($SuspendedMsgs){
# For each suspended message
$SuspendedMsgs | ForEach-Object {
Write-host "---------"
$ConvertedDate = [datetime]::ParseExact($_.ActivationTime.Substring(0,14),'yyyyMMddHHmmss',[Globalization.CultureInfo]::InvariantCulture )
Write-host "Suspended message on service name:"$_.ServiceName"from"$ConvertedDate" will be deleted!"
}
# Start terminating!
Write-host "---------"
Write-host "Termination started..."
$SuspendedMsgs.Terminate() | Out-null
Write-host "Termination completed!"
} else {
write-host "No suspended messages found!"
}