SMLets - New-SCSMProblem??

Aug 29, 2011 at 5:56 PM

Is there a "New-SCSMProblem' cmdlet in the works? If not, it would be hugely helpful to be able to utilize a cmdlet to create a new PM ticket and associate incidents with it.

Does anyone have a script that creates a PM Ticket and Links an Incident to the newly created PM?

It would be greatly appreciated. 

Developer
Aug 29, 2011 at 10:28 PM

i hadn't thought about creating a new-scsmproblem cmdlet, but it shouldn't be hard. What would you like it to do?

It should be possible to create one in script with the New-SCSMObjectProjection command, do you need it to cover all the possibilities, or just some?

Aug 30, 2011 at 10:19 PM

Basically I was trying to get New-SCSMObjectProjection to create a new problem, but was unsuccessful. Overall, I think it would be great to have all the functionality of creating, viewing, resolving a PM from powershell. I am looking at automating Auto-Creation of PMs under alerting conditions from Operation Manager. Many alerts will come in due to an outage, in turn I would like to be able to automatically create a PM ticket and link the incidents that were generated from the outage within the PM utilizing a PowerShell script that runs every few minutes. For example:

** Please note this script does not work.

$PMClass = Get-SCSMClass -name System.WorkItem.Problem$

$GetIncidents = get-scsmincident -CreatedAfter (Get-Date).AddSeconds(-60) -Status "Active" -Source "Operations Manager" -Title "Health Service Heartbeat Failure"

$CountIncidents = ($GetIncidents).Count


If ($CountIncidents -ge 0)

{

New-SCSMObject -Class $PMClass -PropertyHashtable (@{Title = "Test Problem"; Urgency = High; Impact = High}

}

Aug 31, 2011 at 2:44 PM

Oh, also to be able to detect all incidents generated by the same configuration Item and be able to link them into a ticket would be awesome.

Aug 31, 2011 at 2:59 PM

Maybe it's not working because of the time zone?

You're using Get-Date (local time) compared to what the command will get you (I think GMT). Try replacing Get-Date for Get-GMTDate:

function Get-GMTDate () {
    $LocalZone = [System.TimeZoneInfo]::Local
    $Hours = [system.Math]::Abs($LocalZone.BaseUtcOffset.Hours)
    $Mins = [System.Math]::Abs($LocalZone.BaseUtcOffset.Minutes)
    if ($LocalZone.IsdaylightSavingTime([system.DateTime]::Now)) { $Hours -= 1 }
    $TimeDiff = New-Object TimeSpan 0,$Hours,$Mins,0,0
    (Get-Date).Add($TimeDiff)
}