Archive | PowerShell

Create Request Offering with PowerShell in Service Manager 2012

This is an step by step example on how to create a Service Offering with PowerShell. Before running the PowerShell commands install SMLets and import the module into the PowerShell prompt.

# Some variables
$OfferingOwner = “User01”
$PublishedBy = “User01”
$MPName = “Example”
$TemplateDisplayName = “Example”
$ROName = “Example”
$RONotes = “Created by PowerShell”
$RODescription = “Example”

# Get the MP where the Request Offering will be placed
$MP = Get-SCSMManagementPack -Name $MPName

# Get the Template that should be added to the Request Offering
$ObjTemplate = Get-SCSMObjectTemplate -DisplayName $TemplateDisplayName

# Create questions for the Request Offering.
# The Prompt is the User Prompts or Information.
# The TargetPath is the Map Prompts.
# The Type is the Configure Prompts.
$QU = @()
$QU += @{Prompt = “Question One”; TargetPath = “Title”; Type = “String”}
$QU += @{Prompt = “Question Two”; TargetPath = “Notes”; Type = “String”}
$QU += @{Prompt = “Question Three”; TargetPath = “UserInput”; Type = “InlineList”; ListElements = “one”}
$QU += @{Prompt = “Question Four”; TargetPath = “RequiredBy”; Type = “DateTime”}
$enum = Get-SCSMEnumeration ServiceRequestAreaEnum$
$QU += @{Prompt = “Question Five”; TargetPath = “Area”; Type = “List”; EnumerationList = $enum}

# Prepare the questions for adding them to the Request Offering
$Qlist = @()
foreach ($Q in $QU)
{
$Qlist += New-SCSMRequestOfferingQuestion @Q -ea Stop
}

# Get the publisher user from SCSM
$ROPublishedBy = get-scsmuser.ps1 | where {$_.DisplayName -eq $PublishedBy}

# Get the offering owner from SCSM
$ROUser = get-scsmuser.ps1 | where {$_.DisplayName -eq $OfferingOwner}

# Create the input for the new Request Offering
$RO = @{
ManagementPack = $MP
Questions = $Qlist
DisplayName = $ROName
Title = $ROName
TargetTemplate = $ObjTemplate
Notes = $RONotes
BriefDescription = $RODescription
Owner = $ROUser
PublishedBy = $ROPublishedBy
Status = $published
PublishDate = (get-date)
# Image = Get-IconStream $ICON
# NoCommit = $true
}

# Create Request Offering
New-SCSMRequestOffering @RO

4

Change status in Service Manager 2012 with PowerShell

If you need to change the status of a Service Request in Service Manager 2012 you can do this with PowerShell. Here is an example.

Before running the PowerShell commands install SMLets and import the module into the PowerShell prompt.

Example

Import-Module SMLets
$Class = Get-SCSMClass -Name System.WorkItem.ServiceRequest$
Get-SCSMObject -Class $Class -filter “Id -eq SR10” | Set-SCSMObject -Property Status -Value InProgress

Other status values that can be used

Closed
Completed
Cancelled
Failed
Submitted
New
Active
Resolved
Pending
Editing

Other classes that can be used

System.workitem.ChangeRequest$
System.workitem.Incident$
System.workitem.Problem$
System.workitem.ReleaseRecord$

0

Create Management Pack and Template in Service Manager with PowerShell

This post will describe how to create a Management Pack (MP) and a Template in Service Manager with PowerShell.

Before running the PowerShell commands install SMLets and import the module into the PowerShell prompt.

Create MP and Template

# Variables
$MPName = “Example”
$TemplateName = “Example”
$TemplateDescription = “Example”

# Create a new Management Pack
New-SCManagementPack -ManagementPackName $MPNAME -FriendlyName $MPNAME -DisplayName $MPNAME -version 7.5.1335

# Get the newly created Management Pack
$MP = Get-SCSMManagementPack “^${MPNAME}$”

# Get the Class. In this example the Class Service Request is selected
$Class = Get-scsmclass -Name System.Workitem.ServiceRequest$

# Create the Service Request Template
New-SCSMObjectTemplate  -DisplayName $TemplateName -ManagementPack $MP -Class $Class -Name $TemplateName -Description $TemplateDescription

Check if MP and Template been created

Get-SCSMManagementPack -Name <MPName>

Get-SCSMObjectTemplate -DisplayName <Template DisplayName>

2

Find the Application Name from a Configuratin Item ID (CI_UniqueID) in Configuration Manager 2012

This will describe how to search for an application when all you know is the CI_UniqueID of the application. One example, when you might have use for this, is when you read the SCCM logs and only find the CI_UniqueID of the application.

I will describe how to search for the application name and more information in the console and by PowerShell with only the CI_UniqueID as input.

Search with PowerShell

Import-Module ‘C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1’
Set-Location <site code>: (example: cd P01:)
$ApplicationID = “<Configuration Item Unique ID>”
Get-CMApplication | where {$_.CI_UniqueID -match $ApplicationID}

Search in the Console

Add the “CI Unique ID” at the top bar in the main window (see picture below). Pased the CI_UniqueID in the “Search Field” under Applications in Software Library and hit Search.

Find the Application Name from a Configuratin Item ID (CI_UniqueID) in Configuration Manager 2012_1

Another way is to pass the CI_UniqueID to the “Search all objects Files” under Administration -> All Objects and hit Search.

Find the Application Name from a Configuratin Item ID (CI_UniqueID) in Configuration Manager 2012_2

1