Service Manager Announcements   Leave a comment

I’ve written in previous blogs on how to get data out of Service Manager, and generally, that data is usually simple text, numbers or sometimes an enumeration (which is pretty easy to convert to text). However, Service Manager also allows you to store text with formatting (rich text data) which can be pretty difficult to view. First, let’s create an announcement:

We can use one of the scripts created in an earlier posting to retrieve an instance of the announcement:

PS> get-smclass announcement.item|get-scsmobject|fl
Id             : 2
Title          : Announcement 001
Body           : {\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0
                 Times New Roman;}{\f2\fcharset0 Sego
                 e UI;}{\f3\fcharset0 Calibri;}{\f4\fcharset0 Copperplate Gothic
                 Bold;}}{\colortbl\red0\green0\blue0;\r
                 ed255\green255\blue255;\red255\green0\blue0;}
                 {\*\listtable
                 {\list\listtemplateid1\listhybrid
. . .
                 b0\jclisttab\tx720\fi-360\ql\par}
                 }
                 }
ExpirationDate : 6/28/2010 7:00:00 AM
Priority       : System.Announcement.PriorityEnum.Medium
DisplayName    : Announcement 001
Type           : System.Announcement.Item
Name           : 2
Path           :
FullName       : System.Announcement.Item:2

Since the body property of the announcement is rich text, it really isn’t readable in this format, but we can fix that with a fun little script. This is one of those scripts that allow us to mix the command line and the graphical environment. We’ll call this script Display-RichText.ps1 since that’s what it does!

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
param (
$string
)
begin
{
[void][reflection.assembly]::LoadWithPartialName(“System.Windows.Forms”)
[void][reflection.assembly]::LoadWithPartialName(“System.Drawing”)
## the form
$form = new-object System.Windows.Forms.Form
$form.size = new-object System.Drawing.Size 400,400 

## the Rich text box
$text = new-object System.Windows.Forms.RichTextBox
$text.multiline = $true
$text.dock = “Fill”
$text.scrollbars = “Both”
$text.width = 80

## Quit button
$QuitButton = new Windows.Forms.Button
$QuitButton.Name = “QuitButton”
$QuitButton.TabIndex = 0
$QuitButton.Text = “Quit”
$QuitButton.UseVisualStyleBackColor = $true
$QuitButton.Add_Click({$form.dispose()})
$QuitButton.Dock = “Bottom”

$form.controls.add($text)
$form.controls.add($QuitButton)
function loadtext
{
param ( $string )
try
{
$bytes = [byte[]]($string.ToCharArray())
$stream = new-object io.memorystream $bytes,$true
$text.loadfile($stream, “richtext”)
$text.DeselectAll()
[void]$form.showdialog()
}
finally
{
$stream.close()
$stream.dispose()
}
}

}
end
{
loadtext $string
}

Now let’s see what we can do!

PS> $announcement = get-smclass announcement.item|get-scsmobject
PS> display-richtext $announcement.body

Now we can see the contents of the announcement!

Advertisements

Posted June 13, 2010 by jtruher3 in ServiceManager

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

%d bloggers like this: