none
Best way to handle result to a support case like IR/SR for SCSM RRS feed

  • Question

  • Hi,

    I have some issue to to handle the result I got and to got it a good format. I do have control over to get the result with SQL query or Powershell. but my issue is how to get the text into a mail or to a SCSM SR/IR in right format. I would like to add that we have to run the extracting data with a special account.

    ex.

    I would like to get devices from SCCM that is not function as expected, so I create an array of objects

    $Devices = Get-CMDevice -CollectionID PSS00552 | Where-Object {($_.ClientActiveStatus -eq "0" -or ($_.IsObsolete -eq $true))}

    This will work just fine if the Runbook Service had had the right to access the SCCM, but I have to execute this with another account.

    So I run the command with Invoke-Command with the account that have access to SCCM.

    $Devices = Get-CMDevice -CollectionID PSS00342 | Where-Object {($_.ClientActiveStatus -eq "0")}
    Hash table
    $objResult | Select-Object Name, Client, Active, Approved, Check, Obsolete | Out-File -FilePath D:\vk\Result.txt

    For example the result in the D:\vk\Result.txt is what I am looking for, but I cant get the result into a mail or SCSM, if I not jump over a textfile.

    I can do similar with a SQL query but if there result is more complex like a array, it is very hard to hande it in the Orchestratror data bus as a variable.

    Name 
    Server1
    Server2

    So how can I handle arrays of strings, as a variable in Orchestrator and not jump over txt files.  


    /SaiTech

    Monday, October 7, 2019 12:53 PM

Answers

  • Hi,

    to specify credentials you can use a WMI query like

    $CollectionMembers = Get-WmiObject -ComputerName $SiteServer -Credential $YourPSCreds -Namespace "root\SMS\site_$($SiteCode)" -Query "SELECT name FROM SMS_FullCollectionMembership WHERE CollectionID='$($SCCMCollectionID)'" 
    
     

    I guess your Invoke-Command looks like this:

     $CollectionMembers = Invoke-Command -ComputerName  $SiteServer -Credential $YourPSCreds -ScriptBlock {
       $Devices = Get-CMDevice -CollectionID PSS00342 | Where-Object {($_.ClientActiveStatus -eq "0")}
       return $Devices
     }


    With both you can define an array for each attribute, add each result to it and define the array in "Published Data". So the next Activities are triggered for each result and you can access each single attribute:

     $Name = @()
     $Client = @()
     $Active = @()
     $Approved = @()
     
     foreach ($item in $CollectionMembers)
     {
        $Name += $item.Name
        $Client += $item.Client
        $Active += $item.Active
     }
    
     

    If you want a table to send with email you can do something like below, define $line in "Published Data" and flatten the Activity using line breaks to get only one trigger:

     $line = @()
     foreach ($item in $CollectionMembers)
     {
        $line += "$item.Name;$item.Client;$item.Active"
     }

    Regards,

    Stefan


    More and news about System Center at stillcool.de and sc-orchestartor.eu .

    • Proposed as answer by Andreas BaumgartenMVP Tuesday, October 8, 2019 10:15 AM
    • Marked as answer by SaiTech Friday, October 11, 2019 1:51 PM
    Monday, October 7, 2019 6:37 PM
    Answerer

All replies

  • Hi,

    to specify credentials you can use a WMI query like

    $CollectionMembers = Get-WmiObject -ComputerName $SiteServer -Credential $YourPSCreds -Namespace "root\SMS\site_$($SiteCode)" -Query "SELECT name FROM SMS_FullCollectionMembership WHERE CollectionID='$($SCCMCollectionID)'" 
    
     

    I guess your Invoke-Command looks like this:

     $CollectionMembers = Invoke-Command -ComputerName  $SiteServer -Credential $YourPSCreds -ScriptBlock {
       $Devices = Get-CMDevice -CollectionID PSS00342 | Where-Object {($_.ClientActiveStatus -eq "0")}
       return $Devices
     }


    With both you can define an array for each attribute, add each result to it and define the array in "Published Data". So the next Activities are triggered for each result and you can access each single attribute:

     $Name = @()
     $Client = @()
     $Active = @()
     $Approved = @()
     
     foreach ($item in $CollectionMembers)
     {
        $Name += $item.Name
        $Client += $item.Client
        $Active += $item.Active
     }
    
     

    If you want a table to send with email you can do something like below, define $line in "Published Data" and flatten the Activity using line breaks to get only one trigger:

     $line = @()
     foreach ($item in $CollectionMembers)
     {
        $line += "$item.Name;$item.Client;$item.Active"
     }

    Regards,

    Stefan


    More and news about System Center at stillcool.de and sc-orchestartor.eu .

    • Proposed as answer by Andreas BaumgartenMVP Tuesday, October 8, 2019 10:15 AM
    • Marked as answer by SaiTech Friday, October 11, 2019 1:51 PM
    Monday, October 7, 2019 6:37 PM
    Answerer
  • Thanks Stefan Horz, I will test this.

    /SaiTech

    Friday, October 11, 2019 11:50 AM
  • Hi again Stefan,

    I noticed I made a mistake with "Published Data" i was taken $Devices and not the $CollectionMembers. And now I just have the array to fix.

    $CollectionMembers = Invoke-Command -ComputerName  $SiteServer -Credential $YourPSCreds -ScriptBlock {
       $Devices = Get-CMDevice -CollectionID PSS00342 | Where-Object {($_.ClientActiveStatus -eq "0")}
       return $Devices
     }


    /SaiTech

    Friday, October 11, 2019 1:51 PM