Search

Tuesday, November 26, 2013

Some useful scripts for SCSM 2012

Hi,

I write down some usefull Powershell scipts that I use in SCSM 2012. Mostly they are close to each other in logic, but minor changes returns different results. I recommend you check these and modify according to your needs.


#Closed and resolveddate is null and adding 2 days to resolved date as closeddate
$Incidents = @(Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) | Where-Object {$_.Status -like "*Closed" -and $_.ResolvedDate -eq $NULL})
foreach ($Inc in $Incidents)
{
Set-SCSMObject -Property ResolvedDate -Value ($Inc.ClosedDate).AddDays(-2) -SMObject $Inc
}

 

 
 

#Status Closed but no Closeddate inserted, assigning last modified date as closeddate $Inc1 = @(Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) | Where-Object {$_.Status -like "*Closed" -and $_.ClosedDate -eq $NULL})
foreach ($Inc in $Inc1)
{
$Inc | set-scsmobject -Property ClosedDate -Value $Inc.LastModified
write-host $Inc.Name $Inc.ClosedDate
}

 

 

#Getting the time difference between lastmodified and resolveddate  $Last = @(Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) | Where-Object {$_.Status -like "*Closed*" -and $_.closedDate -eq $NULL})
foreach ($L in $Last)
{
$fark = ($L.lastmodified-$L.resolvedDate).duration()
write-host $L.Name /created/ $L.createddate /resolved/ $L.resolveddate /saat/ $fark.TotalHours
}

 

 

#Status Closed but closeddate is empty, Adding 2 days to Resolveddate as a closeddate value $Incidents = @(Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) | Where-Object {$_.Status -like "*Closed" -and $_.closedDate -eq $NULL})
foreach ($Inc in $Incidents)
{
Set-SCSMObject -Property ClosedDate -Value ($Inc.ResolvedDate).AddDays(2) -SMObject $Inc
}

No comments:

Post a Comment