Some more SMlets commands (more detail)

Posted: July 18, 2011 in Powershell
Tags: , , ,

Would you like a nice graphical breakdown of all calls logged in (x) days and there status?

I know I would. So, of course I have been working on such a script using smlets v3.

So far, this is what the script does.

  1. Takes the current date and time and subtracts 7 days and presents you with a nice HTML output which is mailed to the user. (Both the date and time and who to mail the output to is configurable.)
  2. Uses the same date and time as configured above and creates a breakdown of all calls/cases created after said time. Provides a breakdown of these calls in terms of open, closed, resolved and all other statuses.

I am currently working on a way to automate this more and provide a breakdown of calls per user for the above timeframe as well.

Working with get-scsmincident and get-scsmclass is tricky and I am also looking for any ideas on how to achieve this. More to come as soon as possible.

Anyways, code below.

Import-Module smlets

$startdate = $(Get-Date).AddDays(-7)

#buillding folder path
$dir = $env:userprofile
$date = ((Get-Date).toString('yyyMMdd'))
$filepath = $dir.tostring() + "\" +$date + "\"
New-Item -path $filepath -ItemType Directory -ErrorAction "SilentlyContinue"

#building html style
$htmlstyle = "<style>"
$htmlstyle = $htmlstyle + "BODY{background-color:Green;}"
$htmlstyle = $htmlstyle + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$htmlstyle = $htmlstyle + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:GreenYellow}"
$htmlstyle = $htmlstyle + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$htmlstyle = $htmlstyle + "</style>"

#specifying file to attach to e-mail later
$filename = $filepath + "allinc.html"

#building the file and contents of all calls and piping this out a html which will be later added to the e-mail
$createdincidentsfull = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver> |
Select-Object -Property AffectedUser, ID, Status, AssignedTo |
Sort-Object -Property Status |
ConvertTo-Html -Head $htmlstyle | Out-File $filename

#getting the information from Service Manager to supply a count of respective calls.
$createdincidents = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver>
$resolvedincidents = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver> -Status "Resolved"
$closedincidents = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver> -Status "Closed"
$countresolved = $resolvedincidents.count
$countclosed = $closedincidents.count
$countpending = $countcreated - $countresolved - $countclosed

#building message content
$line1 = "Number of calls created after" + " " + $startdate + " " + "is: " + $createdincidents.count
$line2 = "Number of calls resolved created after" + " " + $startdate + " " + "is:" + $resolvedincidents.count
$line3 = "Number of calls closed after" + " " +  $startdate + " " + "is:" + $closedincidents.count
$line4 = "Number of calls remaining open after" + " " + $startdate + " " + "is:" + $countpending

$messagecontent = @"
$line1 `r`n
$line2 `r`n
$line3 `r`n
$line4 `r`n
"@

$smtpserver = "enter IP address here"
$to = "enter recipient here"
$from = "enter sending e-mail here"
Send-MailMessage -To $to -From $from -Body $messagecontent -SmtpServer $smtpserver -Attachments $filename -Subject "Call breakdown"

File can be found here

Anyone who is interested in playing with get-scsmclass (incidents in particular).

The below might be interesting.

Get-SCSMObject -Computername "<nameoripofservicemanagerserver>" –Class (Get-SCSMClass -ComputerName <nameoripofservicemanagerserver> -Name System.WorkItem.Incident$) | gm | Format-Table -AutoSize -Wrap |Out-File <path>

 

Hope this helps,

Follow me

facebook-small32222 twitter-small32222

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s