Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

AADApplication: Using Global Admin works but Service Principal does not

Open Kikaider opened this issue 5 years ago • 2 comments

Details of the scenario you tried and the problem that is occurring

Try to extract AADApplication using the following cmd (where $com = "AADApplication") results in an "empty" file. No errors generated.

Export-M365DSCConfiguration -Quiet -componentsToExtract @($com) -FileName $fileName -Path $path -ConfigurationName $configurationName -ApplicationID $AppID -TenantId $Tenant -CertificateThumbprint $ThumbPrint

results in:

# Generated with Microsoft365DSC version 1.21.407.1
# For additional information on how to use Microsoft365DSC, please visit https://aka.ms/M365DSC
Configuration Contoso-AADApplication-Config
{
    $OrganizationName = $ConfigurationData.NonNodeData.OrganizationName
    Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.21.407.1'

    Node localhost
    {
    }
}
Contoso-AADApplication-Config -ConfigurationData .\ConfigurationData.psd1

But using the following cmd (with Global Admin) returns a full result.

Export-M365DSCConfiguration -Quiet -componentsToExtract @($com) -FileName $fileName -Path $path -ConfigurationName $configurationName -GlobalAdminAccount $Credential

# Generated with Microsoft365DSC version 1.21.407.1
# For additional information on how to use Microsoft365DSC, please visit https://aka.ms/M365DSC
param (
    [parameter()]
    [System.Management.Automation.PSCredential]
    $GlobalAdminAccount
)

Configuration Contoso-AADApplication-Config
{
    param (
        [parameter()]
        [System.Management.Automation.PSCredential]
        $GlobalAdminAccount
    )

    if ($null -eq $GlobalAdminAccount)
    {
        <# Credentials #>
        $Credsglobaladmin = Get-Credential -Message "Global Admin credentials"

    }
    else
    {
        $Credsglobaladmin = $GlobalAdminAccount
    }

    $OrganizationName = $Credsglobaladmin.UserName.Split('@')[1]
    Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.21.407.1'

    Node localhost
    {
        AADApplication asdfas-asdfa-asdf-asdfa-asdfasdfasdfasdf
        {
            AppId                      = "abcdefg-1111-2222a-90eb-128fjfg8jfjfjfjfjf";
            AvailableToOtherTenants    = $False;
            ....

API permissions granted to service principal include: image

Verbose logs showing the problem

N/A

Suggested solution to the issue

N/A

The DSC configuration that is used to reproduce the issue (as detailed as possible)

N/A

The operating system the target node is running

OsName               : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

and also:

OsName               : Microsoft Windows 10 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2004
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US} 

Version of the DSC module that was used ('dev' if using current dev branch)

1.21.407.1

Kikaider avatar Apr 12 '21 15:04 Kikaider

@Kikaider Go into AAD portal under Roles and administrators and select directory reader or writer depending on use > add assignments and your service principal.

desmay avatar Apr 15 '21 18:04 desmay

That worked! Thank you.

Kikaider avatar Apr 30 '21 00:04 Kikaider