Skip to content

[Feature]: Expose SdkModels #27995

Open
Open
@TheKrisSodroski

Description

@TheKrisSodroski

Description of the new feature

We've made a concerted effort to utilize classes significantly in our workloads and it has yielded great success.

One pain point is that it's very easy to lose type information in powershell (or sometimes it seems, impossible). Exposing SDK types in AzModule, MsGraph module, etc would be highly beneficial.

The below code works completely fine with intelisense, and provides amazing visibility while developing, but it does not work at runtime.

function Get-ResourceType([Microsoft.Azure.Commands.Resources.Models.PSResource] $Resource)
{
    # Will return the ResourceType of the AzResource 
    #Examples: ResourceGroup, StorageAccount, SqlServer, KeyVault, etc

    #using $Resource in this block gives great typeinfo support.
}

# Any type of AzResource, 
$AzResources = @();

foreach ($resource in $AzResources)
{
    $resourceType = Get-ResourceType -Resource $resource

    if ($resourceType -eq "ResourceGroup")
    {
        $resourceGroup = [Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResourceGroup] $resource;

        # Get great typeinfo support now from $resourceGroup
        $typeInfoWorks = $resourceGroup.ResourceGroupName;
    }
     # more switching on resourceType 
}
Unable to find type [Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResourceGroup].

As a workaround, we've been doing the following so we can "toggle on/off" typing.

function Get-ResourceType(
    # Toggle this on and the other arg off to get intellisense support.
    # [Microsoft.Azure.Commands.Resources.Models.PSResource] 
    # $Resource
    [PSCustomObject] 
    $Resource

)
{
    # Will return the ResourceType of the AzResource 
    #Examples: ResourceGroup, StorageAccount, SqlServer, KeyVault, etc
}

# Any type of AzResource, 
$AzResources = @();

foreach ($resource in $AzResources)
{
    $resourceType = Get-ResourceType -Resource $resource
    if ($resourceType -eq "ResourceGroup")
    {
        # Toggle this on and the other arg off to get intellisense support.
        # $resourceGroup = [Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResourceGroup] $resource;
        $resourceGroup = $resource;

        # No more intellisense support ;(
        $typeInfoWorks = $resourceGroup.ResourceGroupName;
    }
    # more switching on resourceType 
}

Oddly enough, some types work, sometimes... (though, none from Az that I've found).

For example, it seems that if Graph is loaded once, [Microsoft.Graph.PowerShell.Models.MicrosoftGraphGroup] is available to use at runtime. But it always fails the first time, despite force calling Import-Module Microsoft.Graph or Connect-MgGraph, or tying to use "using".

I see that the .dlls for the SdkModels are denoted as "private." Is there a way we can get some sdk model base that we can start to use in greenfield powershell projects?

Proposed implementation details (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedfeature-requestThis issue requires a new behavior in the product in order be resolved.needs-triageThis is a new issue that needs to be triaged to the appropriate team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions