Access Lazy properties in power shell code while reading SCCM classes

Shreedhar Ghare 0 Reputation points
2023-08-31T07:29:33.42+00:00

Hello All

I am trying to read MECM (SCCM) server through Rest API. but while accessing SMS_Program class, I am unable to read SupportedOperatingSystems property in powershell code. As SupportedOperatingSystems is Lazy property object is fetching blank value. 

Power Shell  Commands:

$uri = "https://Localhost.Ghare/AdminServices/wmi/SMS_Program"

$resp = Invoke-RestMethos -Uri $uri -userDefaultCredentials

$resp.values

Output:

SupportedoperatingSystems:  

{}

Could you please help us to fetch Lazy properties in Powershell script?  

Microsoft Configuration Manager Application
Microsoft Configuration Manager Application
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Application: A computer program designed to carry out a specific task other than one relating to the operation of the computer itself, typically to be used by end users.
460 questions
Microsoft Configuration Manager
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,132 questions
{count} votes

2 answers

Sort by: Most helpful
  1. AllenLiu-MSFT 41,131 Reputation points Microsoft Vendor
    2023-09-01T06:29:47.33+00:00

    Hi, @Shreedhar Ghare

    Thank you for posting in Microsoft Q&A forum.

    To read lazy properties from a Configuration Manager object returned in a query, you need to get the object instance, which in turn retrieves any lazy object properties from the SMS Provider.

    In the PowerShell script provided, you are using the Invoke-RestMethod cmdlet to retrieve the SMS_Program class, but it is not returning the value for the SupportedOperatingSystems property.

    To access lazy properties in PowerShell, you can use the Get-WmiObject cmdlet with the -Property parameter to specify the lazy property you want to retrieve. Here is an example of how you can modify your PowerShell script to retrieve the SupportedOperatingSystems lazy property:

    $uri = "https://Localhost.Ghare/AdminServices/wmi/SMS_Program"
    
    $program = Invoke-RestMethod -Uri $uri -UseDefaultCredentials
    
    $programInstance = Get-WmiObject -Namespace $program.NamespacePath -Class $program.ClassName -Filter "LocalizedDisplayName='$($program.LocalizedDisplayName)'" -ComputerName $program.MachineName -Impersonation 3 -Authentication 6 -Property SupportedOperatingSystems
    
    $programInstance.SupportedOperatingSystems
    
    

    This script retrieves the SMS_Program class using the Invoke-RestMethod cmdlet and then uses the Get-WmiObject cmdlet to retrieve the SMS_Program instance and the SupportedOperatingSystems lazy property.

    The -Namespace parameter specifies the namespace of the class, the -Class parameter specifies the name of the class, the -Filter parameter specifies the filter to apply to the class, and the -Property parameter specifies the lazy property to retrieve.

    The script then outputs the value of the SupportedOperatingSystems property.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Add comment".


  2. Shreedhar Ghare 0 Reputation points
    2023-09-05T08:05:12.01+00:00

    @AllenLiu-MSFT

    Thank you for your response, But Get-wmiobject method is not working in this case.

    When I am executing below Command

    $programInstance = Get-WmiObject -Namespace $program._NAMESPACE -Class $program.__CLASS -Filter PackageID = "12345" -ComputerName "Localhost.Ghare" -Impersonation 3 -Authentication 6 -Property SupportedOperatingSystems

    Getting below Error

    get-wmiobject : Generic failure

    But below command works without Authentication and Property parameters

    $programInstance = Get-WmiObject -Namespace $program._NAMESPACE -Class $program.__CLASS -Filter PackageID = "12345" -ComputerName "Localhost.Ghare" -Impersonation 3

    We also tried SWbemLocator class but still unable to read SupportedOperatingSystems

    0 comments No comments