In this post I will show how to make a bulk update of Service Owner and Serviced By User relations on specific Business Services.
Since these relations are located on the System.Service class, which is abstract, we can’t use a regular CSV import in Service Manager.
However, we can solve it with some Powershell magic and SMLets.
You need to start with installing SMLets and load it in a powershell console (http://smlets.codeplex.com/)
Then you need to prepare your import data. It should be saved as a CSV-file with semicolon separation, and contain the following columns:
- Displayname of the Business Service ; sAMAccountName of the Service Owner ; sAMAccountName of the Serviced By User
Here is one example of two rows:
Active Directory;user123;user456
Exchange;user123;user456
- Name the CSV-file “input.csv” and put it in your c:\temp directory
- Copy the powershellscript to the same directory
- Run the script. The script will search for the displayname, and then update the relations for each row.
- All updated services will be logged to the file “updated.txt”
- If some service coudn’t be found and updated, they will be logged to “failed.txt”
Powershell script:
$input = Get-Content C:\temp\input.txt
$row = $null
$ServiceOwner_RelClass = Get-SCSMRelationshipClass System.ConfigItemOwnedByUser$
$ServiceResp_RelClass = Get-SCSMRelationshipClass System.ConfigItemServicedByUser$
Foreach ($row in $input)
{
$data = $null
$service_displayname = $null
$owner_user = $null
$resp_user = $null
$data = $row.Split(";")
$service_displayname = $data[0]
$owner_user = $data[1]
$resp_user = $data[2]
$service = $null
$row2 = $null
$ServiceOwner = $null
$ServiceResp = $null
#Check array for all columns
If ($data.Length -eq 3)
{
$service = get-scsmobject (get-scsmclass System.Service$) -Filter "Displayname -eq '$service_displayname'"
#Service not found?
If ($service -eq $null)
{
Write-Host "$service_displayname not found!" -ForegroundColor Red
$service_displayname | Out-File c:\temp\failed.txt -Append}
#Service found!
Else
{
$service_displayname + " = " + $service.Displayname
$Service.Displayname | out-file c:\temp\updated.txt -Append
$ServiceOwner = Get-SCSMObject -Class (Get-SCSMClass Microsoft.AD.User$) -filter "Username -eq '$owner_user'"
$ServiceResp = Get-SCSMObject -Class (Get-SCSMClass Microsoft.AD.User$) -filter "Username -eq '$resp_user'"
New-SCSMRelationshipObject -Relationship $ServiceOwner_RelClass -Source $Service -Target $ServiceOwner -Bulk
New-SCSMRelationshipObject -Relationship $ServiceResp_RelClass -Source $Service -Target $ServiceResp -Bulk
}
}
}
