new-scsmincident get id of this new incident?

Hi Together,

i posted this allready over in the codplex forum but i`m not sure if its correct over there. Thats why i post it here again:

Currently i'm working on a Script with which i can import Tickets from another Ticketsystem via CSV. 

I managed to do that because its quite easy with the new-scsmincident cmdlet. 

But now i should have the ID of the newly created incident to add the assigned to user to the incident. 

Actually i try it with: 

$id = (Get-SCSMIncident -Title "$ticketidmx + $title").id 

Because i save the ticket-id of the other Ticketsystem and the title of the incident in the new incident in SCSM. 

But i think that's not "save" enough. 

So is there any possibility to get the ID of the newly created incident directly after creating it with new-scsmincident? 

thank you 

brgds

January 17th, 2015 6:07pm

Here is an example. I create an incident and i get the ID from the incident we just created and i apply a template. 

$ID = "IR{0}" # Set low impact/urgency if a template is being used it will override this settings anyway.

$IRClass = Get-SCSMClass -Name 'System.WorkItem.Incident$'

$IR_Urgency = Get-SCSMEnumeration -Name System.WorkItem.TroubleTicket.UrgencyEnum.Low$ $IR_Impact = Get-SCSMEnumeration -Name System.WorkItem.TroubleTicket.ImpactEnum.Low$ New-SCSMOBject -Class $IRClass -PropertyHashtable (@{Title = $subject; Description = $body; ID = $ID; Impact = $IR_Impact; Urgency = $IR_Urgency;}) -PassThru -OutVariable NewObject $IncidentRequest = Get-SCSMObjectProjection System.WorkItem.Incident.ProjectionType -filter "Id -eq $($NewObject.Id)" $IncidentRequest.__base.ApplyTemplate($IncidentTemplate) $IncidentRequest.__base.Commit()


Hope this helps. I am not using the new-scsmincident but this works just as good, we pass variables to a new object and we can use that to get the ID.

It requires SMlets btw. 

Free Windows Admin Tool Kit Click here and download it now
January 17th, 2015 6:41pm

Hi Thomas,

you work with the new-scsmobject cmdlet. 

Is the same not possible with the new-scsmincident cmdlet? 

my way to create a new incident is: 

New-SCSMIncident -Title "$ticketidmx $title" -Description $descrip -Impact Medium -Urgency Medium -Classification Bug -Status Active -Source Console -AffectedUser "alpla\$affecteduserid" -SupportGroup "CORP CRM" -CreatedDate $createddate

The only disadvantage i dont get the ID from this newly created incident :(

brgds

Chris

January 18th, 2015 12:42am

The New-SCSMincident is just an alias for new-scsmobject created to be more userfriendly. I just tested in my lab if passthru and -outvariable worked on new-scsmincident and i did'nt get it to work. Mabe someone else knows how to do this with new-scsmincident but i only knows how to do it with new-scsmobject. 

Free Windows Admin Tool Kit Click here and download it now
January 18th, 2015 12:50am

Depending on when you are creating these incidents you could get the latest created using 

$Then = (Get-Date).AddSeconds(-10).ToUniversalTime();
Get-SCSMObject -Class (Get-SCSMClass System.WorkItem.Incident$) -Filter "CreatedDate -gt '$Then'" | Sort-Object CreatedDate | Select-Object -Last 1

But you really should use New-SCSMObject (just fetched some random values for impact, urgency, etc.)

$Impact = Get-SCSMEnumeration System.WorkItem.TroubleTicket.ImpactEnum.Low$
$Urgency = Get-SCSMEnumeration System.WorkItem.TroubleTicket.UrgencyEnum.High$
$Classification = Get-SCSMEnumeration IncidentClassificationEnum.Hardware$

$NewIR = New-SCSMObject -Class (Get-SCSMClass System.WorkItem.Incident$) -PropertyHashtable @{Title = "Title"; Description = "Description"; Classification = $Classification; Impact = $Impact; Urgency = $Urgency} -PassThru

January 18th, 2015 8:18pm

Hi,

this worked for me: 

$incidentid = (New-SCSMIncident -Title $title -Description $description -Impact Low -Urgency Medium -Classification "Software Problems" -Source Intranet -AffectedUser $affectedUserLogin -Status "Active" -PassThru).Object

BR

Gabor

Free Windows Admin Tool Kit Click here and download it now
February 22nd, 2015 10:15am

Hi,

this worked for me: 

$incidentid = (New-SCSMIncident -Title $title -Description $description -Impact Low -Urgency Medium -Classification "Software Problems" -Source Intranet -AffectedUser $affectedUserLogin -Status "Active" -PassThru).Object

BR

Gabor

February 22nd, 2015 6:14pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics