2014/09/09

PowerShell/SCSM - Finding the GUID of an object

Retrieving the GUID of an object in SCSM using PowerShell is sometime a bit challenging. For the WorkItems, this piece of information is not present in any Property available, you have to invoke the get_id method to retrieve it.

There is an 'ID' property which is misleading, it contains the number of the request, for example IR123456.

And for some other type of objects, such as the DomainUser or Enumeration objects the GUID is the..... ID property.


Note: I'm using the module SMlets, available here: https://smlets.codeplex.com/

Getting the GUID for a WorkItem

If you look at the property of an Incident for example, you will notice that there is no property that contains the GUID


You will have to use the method get_id() to retrieve this information



Incident Request
# Get a specific Incident Request
$IncidentRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) -filter "ID -eq IR31437"

# Getting the GUID of this Work Item
$IncidentRequest.get_id()




Service Request
# Get a specific Service Request
$ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -filter "ID -eq SR31467"

# Getting the GUID of this Work Item
$ServiceRequest.get_id()



Review Activity
# Get a specific review activity
$ReviewActivity = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity.ReviewActivity$) -filter "ID -eq RA31724"

# Get the GUID of this Work Item
$ReviewActivity.get_id()



ManualActivity
# Get a specific manual activity
$ManualActivity = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity.ManualActivity$) -filter "ID -eq MA45345"

# Get the GUID of this Work Item
$ManualActivity.get_id()



Runbook Activity
# Get a Runbook Activity
$RunbookActivity = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.SystemCenter.Orchestrator.RunbookAutomationActivity$) -filter 'ID -eq RB30579'

# Retrieve the ID property
$RunbookActivity.id

# Retrieve the GUID
$RunbookActivity.get_id()





Getting the GUID for other objects


Domain User
# Query a Domain User from the CMDB
$DomainUser = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.AD.User$) -Filter "LastName -eq Cat"

# Get the GUID of this CI
$DomainUser.id



Domain Computer
# Get a computer object from the CMDB
$ComputerObject = Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.Windows.Computer$) -Filter "Displayname -eq MTLLAP8500"

# Retrieve the ID
$ComputerObject.id

# Retrieve the ID using the Get_ID() method.
$ComputerObject.get_id()






Thanks for reading! If you have any questions, leave a comment or send me an email at fxcat@lazywinadmin.com. I invite you to follow me on Twitter @lazywinadm / Google+ / LinkedIn. You can also follow the LazyWinAdmin Blog on Facebook Page and Google+ Page.

7 comments:

  1. I have visited the site carefully. and read its posts thank you so much for sharing this kind of information. I am sharing a site of msds.It is free printable msds sheets online

    ReplyDelete
  2. Hi Francois-Xavier
    I am not sure if I am being silly or not. I have downloaded the function and have tried to execute it. When I try to add the subnet I get an error: The term 'Add-Subnet' is not recognized.
    Please advise if I am doing something wrong or missing out on something.

    ReplyDelete
  3. Hey Dhillan!
    You need to load the function in your session first.


    You can do the following:


    . c:\scripts\add-adsubnet.ps1


    Notice the dot and space at the beginning of the line. This technique is called Dot Sourcing.
    Once this is done you will be able to use the Add-ADSubnet function.


    Hope this help

    ReplyDelete
  4. Hey

    Thanks for replying. I did get it work after all ... I found that the DASHES in the script name was a problem when I changed this to underscores they worked fine.

    Excellent script really saves me time :) Thanks

    ReplyDelete
  5. Hi.
    not works with me. i don´t know how to.. :(

    ReplyDelete
  6. Hey Claudio, which one did you try ? ADSI or ActiveDirectory module ?
    Could you provide some more information ? what is the error message.

    ReplyDelete