-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSet-DescriptionWithUserInput.ps1
More file actions
93 lines (80 loc) · 2.82 KB
/
Set-DescriptionWithUserInput.ps1
File metadata and controls
93 lines (80 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Import SMlets module
Import-Module smlets -force 2>&1
#------ Variables ------
# ID of the Service Request
$id = "SR320472"
# Name of the SCSM Management Server
$smDefaultComputer = "scsm1"
#----- Magic starts here ------------------
# Get Service Request Class
$srClass = Get-SCSMClass -Name System.WorkItem.ServiceRequest$
#Get Service Request Object
$srObject = Get-SCSMObject -Class $srClass -Filter "Id = $id"
# Get User Input of Service Request
$userInputContent = [XML]$srObject.UserInput
#$userInputContent = [XML]$xmlUserInput
$questions = $userInputContent.UserInputs.UserInput
# Clear useInput variable
$userInput = ""
# If Service Request Description is not empty
if ($srObject.Description)
{
# Build UserInput with existing description
$userInput+= $srObject.Description + [Environment]::NewLine + "---------------" + [Environment]::NewLine
}
# For each line in User Input of SR
foreach ($input in $questions)
{
# If Input contains Answer Value
if($($input.Answer) -like "<Value*")
{
# Set answer variable
[xml]$answer = $input.Answer
# for each answer varaible ...
foreach($value in $answer.Values)
{
# For each item in value variable
foreach($item in $value)
{
# For each text in Item Value
foreach ($txt in $($item.Value))
{ # Build list
$listArray += $($txt.DisplayName)
}
# Build User Input
$userInput += $input.Question + " = " + [string]::Join(" ; ",$listArray) + [Environment]::NewLine
$ListArray = $null
}
}
}
else
{
# If Input Type is a List Value
if ($input.Type -eq "enum")
{
$listGuid = Get-SCSMEnumeration -Id $input.Answer
$userInput+= $($input.Question + " = " + $listGuid.Displayname) + [Environment]::NewLine
}
# If Input Type is Date/Time value
if ($input.Type -eq "datetime")
{
# Set date property
$date = [DateTime]$input.Answer
# Format Date/Time
$date = $date.ToString("dd.MM.yyy")
# Build User Input
$userInput+= $($input.Question + " = " + $date) + [Environment]::NewLine
}
else
{
# Build User Input
$userInput += $($input.Question + " = " + $input.Answer) + [Environment]::NewLine
}
}
}
# Build property has for update
$propertyHash = @{
Description = $userInput
}
# Update of Service Request Description field
$srObject | Set-SCSMObject -PropertyHashtable $propertyHash