Issue with New-MgDeviceManagementWindowAutopilotDeploymentProfile

Cody P 20 Reputation points
2023-07-03T03:55:50.2233333+00:00

I've been attempting to make new Autopilot profiles for a bunch of smaller tenants via MS Graph for PowerShell. When I use the command to create one, I get an error:

Code:

$body = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphWindowsAutopilotDeploymentProfile]@{
    DisplayName                 = "Test Profile"
    Description                 = "Test Profile"
    Language                    = 'En-AU'
    ExtractHardwareHash         = $false
    EnableWhiteGlove            = $true
    DeviceNameTemplate          = '%SERIAL%'
    DeviceType                  = 'windowsPc'
    RoleScopeTagIds             = {0}
    OutOfBoxExperienceSettings=@{
        HidePrivacySettings       = $true
        HideEula                  = $true
        UserType                  = 'Standard'
        DeviceUsageType           = 'singleuser'
        SkipKeyboardSelectionPage = $false
        HideEscapeLink            = $true
    }
    EnrollmentStatusScreenSettings=@{
        hideInstallationProgress                         = $true
        allowDeviceUseBeforeProfileAndAppInstallComplete = $true
        blockDeviceSetupRetryByUser                      = $false
        allowLogCollectionOnInstallFailure               = $true
        customErrorMessage                               = "An error has occured. Please contact your IT Administrator"
        installProgressTimeoutInMinutes                  = "45"
        allowDeviceUseOnInstallFailure                   = $true
    }
}

New-MgDeviceManagementWindowAutopilotDeploymentProfile -BodyParameter $body

Error:

New-MgDeviceManagementWindowAutopilotDeploymentProfile_Create: 
Line |
  29 |  New-MgDeviceManagementWindowAutopilotDeploymentProfile -BodyParameter …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot create an abstract class.

Oddly, if I check [Microsoft.Graph.PowerShell.Models.MicrosoftGraphWindowsAutopilotDeploymentProfile], it's property "IsAbstract" is False.

I may be misunderstanding how to instantiate the object though. Is there anyone who can provide an example of how to complete this?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,799 questions
Microsoft Intune Configuration
Microsoft Intune Configuration
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Configuration: The process of arranging or setting up computer systems, hardware, or software.
1,975 questions
Microsoft Intune Enrollment
Microsoft Intune Enrollment
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Enrollment: The process of requesting, receiving, and installing a certificate.
1,404 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,446 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,744 questions
0 comments No comments
{count} votes

Accepted answer
  1. Crystal-MSFT 51,041 Reputation points Microsoft Vendor
    2023-07-04T01:43:38.6466667+00:00

    @Cody P, Thanks for the update. I am glad the issue is resolved and thanks for sharing the solution here. As you can't mark your reply as answer, to help others who has the same issue, please let me write a summary for our issue:

    Issue:

    Create new Autopilot profiles for a bunch of smaller tenants via MS Graph for PowerShell, but get an error:

    New-MgDeviceManagementWindowAutopilotDeploymentProfile_Create: 
    Line |
      29 |  New-MgDeviceManagementWindowAutopilotDeploymentProfile -BodyParameter …
         |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | Cannot create an abstract class.
    

    Resolution:

    User's image

    Thanks for your time and have a nice day!

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Crystal-MSFT 51,041 Reputation points Microsoft Vendor
    2023-07-03T07:10:53.4333333+00:00

    @Cody P, Thanks for posting in Q&A. Based on my testing, I find one possible affected parameter is the following one. You can remove the following one and see if it can work.

    DeviceNameTemplate = '%SERIAL%'


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Cody P 20 Reputation points
    2023-07-03T12:31:52.1666667+00:00

    Have figured this out finally - I hadn't added @odata.type keys in for the object type:
    Microsoft.Graph.PowerShell.Models.MicrosoftGraphWindowsAutopilotDeploymentProfile.
    This is the key and value pair: '@odata.type' = '#microsoft.graph.azureADWindowsAutopilotDeploymentProfile'

    After I added that, the command worked fine. However I also found that the EnrollmentStatusScreenSettings values didn't have any affect - this makes sense, as within the UI, ESP settings are separate from Autopilot settings. This part of the class is likely just orphaned from before the settings were separated.

    The working code:

    $body = [Microsoft.Graph.PowerShell.Models.MicrosoftGraphWindowsAutopilotDeploymentProfile]@{
        DisplayName                 = "Test Profile"
        Description                 = "Test Profile"
        Language                    = 'En-AU'
        ExtractHardwareHash         = $True
        EnableWhiteGlove            = $True
        DeviceNameTemplate          = '%SERIAL%'
        DeviceType                  = 'windowsPc'
        '@odata.type'               = '#microsoft.graph.azureADWindowsAutopilotDeploymentProfile'
        OutOfBoxExperienceSettings=@{
            HidePrivacySettings       = $true
            HideEula                  = $true
            UserType                  = 'Standard'
            DeviceUsageType           = 'singleuser'
            SkipKeyboardSelectionPage = $false
            HideEscapeLink            = $true
        }
    }
    New-MgDeviceManagementWindowAutopilotDeploymentProfile -BodyParameter $body
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.