0

We want to generate an SR per row based on the criteria of a CSV file looking like:

SR templete

The additional criteria: if the SLO countdown is less than 7 days then the due date is always 7 days for the ticket to be due. Otherwise then then countdown is number SLO _Countdown

The support group is always servicedesk.

Unless the host_name does not contain "RES" then it is the support group is EITS_HW_Notes and it will be assigned to "custodian".

No matter what an SR is generated even if null.

My difficulty is my lack familiarity with smlets. I am happy to consider generating tickets via email as well. But would like help on how best to do that via powershell. But the code I came up with is below:

`#Prod
#$GLOBAL:smdefaultcomputer = "prodserver"
#Test
$GLOBAL:smdefaultcomputer = "testserver"
Import-Module SMlets

$path = "C:\Temp\Test.csv"
$csv = Import-csv -path $path

#Variable / Class Setup
$srClass = Get-SCSMClass -name System.WorkItem.ServiceRequest
$srprior = Get-SCSMEnumeration -Name ServiceRequestPriorityEnum.Medium
$srurg = Get-SCSMEnumeration -Name ServiceRequestUrgencyEnum.Medium
#$ararea = get-SCSMEnumeration -Name ServiceRequestAreaEnum.Other
$ararea = get-SCSMEnumeration -Name Enum.add3768303064ec18890170ba33cffda
$title = “Title Goes Here”
$descrip = "Description info goes here"

#Service Request Arguments
$srargs = @{
Title = $title;
Urgency = $srurg;
Priority = $srprior;
ID = “SR{0}”;
Area = $ararea;
SupportGroup = "ServiceDesk";
Description = $descrip
}

#Create Service Request
$newServiceRequest = New-SCSMOBject -Class $srClass -PropertyHashtable $srargs -PassThru

#get SR ID of the new object
$SRId = $newServiceRequest.id


#Get Projection & Object for Created Service Request
$srTypeProjection = Get-SCSMTypeProjection -name System.WorkItem.ServiceRequestProjection$
$SRProj = Get-scsmobjectprojection -ProjectionName $srTypeProjection.Name -filter “Id -eq $SRId”


#Set Afffected User
$userClass = Get-SCSMClass -Name Microsoft.AD.UserBase$
$cType = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
$cString = "UserName = 'itservicenotifications' and Domain = 'SHERMAN'"
$crit = new-object $cType $cString,$userClass
$user = Get-SCSMObject -criteria $crit
$AffectedUserRel = get-scsmrelationshipclass -name System.WorkItemAffectedUser$
New-SCSMRelationshipObject -RelationShip $AffectedUserRel -Source $newServiceRequest -Target $user -Bulk`

I tried the above code but am running into issues recognizing the column name in the CSV file and am unfamiliar with SMLETS + powershell if statements. Columns are: CSV Columns

CSV text with examples is: Columns with examples

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Could you paste the CSV columns as text, please? Or, better, a sample CSV with one or two rows (redact any sensitive data).

I would expect a CSV to contain multiple rows - even if yours does not, it's good defensive programming to act as if it does. So the first modification I suggest is:

$path = "C:\Temp\Test.csv"
$csv = Import-csv -path $path

foreach ($Row in $csv)
{
    # the rest of your code goes in here
}

I find it helpful while debugging to go step-by-step. If I understand your problem right, it's about building the right hashtable in $srargs to pass to New-SCSMOBject. So the next modification is:

foreach ($Row in $csv)
{
    $srClass = Get-SCSMClass -name System.WorkItem.ServiceRequest
    # etc

    $srargs = @{
        Title        = $title
        Urgency      = $srurg
        Priority     = $srprior
        ID           = “SR{0}”
        Area         = $ararea
        SupportGroup = "ServiceDesk"
        Description  = $descrip
    }

    $srargs   # write the hashtable so you can inspect it
    # skip the rest of the code for now
}

I understand your question as "how to express the logic of":

  • support group is always servicedesk
  • Unless the host_name does not contain "RES"
  • then the support group is contents of EITS_HW_Notes cell in CSV
  • and it will be assigned to "custodian"

I can't help you with setting the assignee. But we can rejig the rest of the statement:

  • if host_name contains "RES"
    • SupportGroup = servicedesk
  • else
    • SupportGroup = contents of EITS_HW_Notes cell

You can code that like this:

foreach ($Row in $csv)
{
    $srClass = Get-SCSMClass -name System.WorkItem.ServiceRequest
    # etc

    if ($Row.host_name -like "*RES*")
    {
        $SupportGroup = "ServiceDesk"
    }
    else
    {
        $SupportGroup = $Row.EITS_HW_Notes
    }

    $srargs = @{
        Title        = $title
        # etc
        SupportGroup = $SupportGroup
        Description  = $descrip
    }
}

Does that get you any closer to your solution?

FSCKur
  • 920
  • 7
  • 16
  • columns are: host_name ip_address Model SCCM PrimaryUser SCSM Custodian Title cve Source RCS_CVSS RCS_Exploits RCS_Severity Patch Age (Days) SLO SLO Countdown date_first_seen last_assessed_for_vulnerabilities SCCM Last Active Time Client_State_Detail Last Restart Days Since Last Restart proof Proof URL OS AD_Site EITS_HW_Notes – TheRapture Jan 31 '23 at 19:50
  • That is getting me closer to the solution! Thank you! I am learning alot about powershell! Now its about trying to get things closer together so the powershell can import SRs into scsm. – TheRapture Jan 31 '23 at 19:54
  • Glad to help, it's a pleasure. If this answer was helpful, would you accept it as an answer? – FSCKur Jan 31 '23 at 23:54