Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

Unauthorized issue - FabricAdminTenantSettings

Open gaborenok opened this issue 1 year ago • 10 comments

Hello Everyone!

I am having an issue with exporting FabricAdminTenantSettings, because of a 401 Unauthorized issue. I cannot find any descriptions or documentation that the permissions are required.

Can anyone help with that, please?

Thank you!

"# Getting application information for Application + Secret authentication $ApplicationId = '****' $ApplicationSecret = '' $TenantId = ''

Exporting resources using application

Export-M365DSCConfiguration -Components @("FabricAdminTenantSettings") -ApplicationId $ApplicationId -CertificateThumbprint $ApplicationSecret -TenantId $TenantId

Error:

[2025/08/11 02:57:44] {InvalidOperation} System.Net.WebException: The remote server returned an error: (401) Unauthorized. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() "Error during Export:" at Invoke-M365DSCFabricWebRequest, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\WorkloadHelpers\M365DSCFabricHelper.psm1: line 23 at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\DSCResources\MSFT_FabricAdminTenantSettings\MSFT_FabricAdminTenantSettings.psm1: line 1999 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCReverse.psm1: line 680 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCUtil.psm1: line 1581 at , : line 6 TenantId: ****

gaborenok avatar Aug 11 '25 13:08 gaborenok

@gaborenok You can follow the blog from @NikCharlebois here: https://nik-charlebois.com/blog/posts/2024/authenticating-to-fabric/index.html The information will be included soon in the M365DSC documentation, a PR is currently pending.

FabienTschanz avatar Aug 11 '25 13:08 FabienTschanz

@FabienTschanz thank you for the helpful and fast response! I will keep you posted about the progress!

gaborenok avatar Aug 11 '25 13:08 gaborenok

Hello!

Do you have any ideas, maybe on this one?

I am trying to export O365OrgSettings

Additionally, I added the permission about 1 hour ago, and I am still receiving unauthorized access on Fabric. Any ideas?


Getting application information for Application + Secret authentication

$ApplicationId = '' $ApplicationSecret = '' $TenantId = '****'

Exporting resources using application

Export-M365DSCConfiguration -Components @("O365OrgSettings") -ApplicationId $ApplicationId -CertificateThumbprint $ApplicationSecret -TenantId $TenantId

ERROR:

[2025/08/11 04:58:42] {NotSpecified} System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Graph.Authentication.Core, Version=2.29.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. at Microsoft.Graph.PowerShell.Module.d__1.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Graph.PowerShell.Module.OnCmdletBeginProcessing(String id, CancellationToken cancellationToken, Func1 getEventData, Func4 signal, InvocationInfo invocationInfo) at Microsoft.Graph.PowerShell.Module.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Module.d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Cmdlets.GetMgServicePrincipal_List.d__90.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at Microsoft.Graph.PowerShell.Cmdlets.GetMgServicePrincipal_List.BeginProcessing() at System.Management.Automation.Cmdlet.DoBeginProcessing() at System.Management.Automation.CommandProcessorBase.DoBegin() ---> (Inner Exception #0) System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Graph.Authentication.Core, Version=2.29.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.Graph.Authentication.Core, Version=2.29.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' at Microsoft.Graph.PowerShell.Module.d__1.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Graph.PowerShell.Module.OnCmdletBeginProcessing(String id, CancellationToken cancellationToken, Func1 getEventData, Func4 signal, InvocationInfo invocationInfo) at Microsoft.Graph.PowerShell.Module.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Module.d__32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Cmdlets.GetMgServicePrincipal_List.d__90.MoveNext()

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. <---

"Error retrieving data:" at Get-MgServicePrincipal, C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Applications\2.28.0\exports\ProxyCmdletDefinitions.ps1: line 32677 at Get-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\DSCResources\MSFT_O365OrgSettings\MSFT_O365OrgSettings.psm1: line 209 at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\DSCResources\MSFT_O365OrgSettings\MSFT_O365OrgSettings.psm1: line 1049 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCReverse.psm1: line 680 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCUtil.psm1: line 1581 at , : line 6 TenantId: 8fck2k.onmicrosoft.com

[2025/08/11 04:58:42] {InvalidOperation} System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression. at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0) at System.Management.Automation.PSScriptCmdlet.RunClause(Action1 clause, Object dollarUnderbar, Object inputToProcess) at System.Management.Automation.PSScriptCmdlet.DoEndProcessing() at System.Management.Automation.CommandProcessorBase.Complete() "Error during Export:" at Get-M365DSCExportContentForResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCUtil.psm1: line 4021 at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\DSCResources\MSFT_O365OrgSettings\MSFT_O365OrgSettings.psm1: line 1051 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCReverse.psm1: line 680 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCUtil.psm1: line 1581 at , : line 6 TenantId: 8fck2k.onmicrosoft.com

Thank you again!

gaborenok avatar Aug 11 '25 15:08 gaborenok

I assume this happens with multiple resources, also for some in the AAD workload like AADApplication or AADServicePrincipal, correct? It seems like you have multiple versions of the Microsoft Graph SDK installed (most like Microsoft.Graph.Authentication). Please uninstall the version 2.29.1 and try again or run Update-M365DSCModule to clean them up automatically.

FabienTschanz avatar Aug 11 '25 19:08 FabienTschanz

Thank you! All issues resolved, you can close this ticket!

gaborenok avatar Aug 12 '25 08:08 gaborenok

Hello, sorry for the inconvenience, but I encountered another (I think permission) issue with SPOSite

I only need read permissions, and I added these:

Application permissions Read Sites.FullControl.All


Export-M365DSCConfiguration -Components @("SPOSite") -ApplicationId $ApplicationId -CertificateThumbprint $ApplicationSecret -TenantId $TenantId

Error: [2025/08/12 04:27:42] {WriteError} Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Attempted to perform an unauthorized operation. at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.d__53.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientRequest.d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientRuntimeContext.d__65.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.d__28.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.SharePoint.Client.ClientContextExtensions.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent) at PnP.PowerShell.Commands.GetTenantSite.ExecuteCmdlet() at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() "Error during Export:" at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\DSCResources\MSFT_SPOSite\MSFT_SPOSite.psm1: line 929 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCReverse.psm1: line 680 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCUtil.psm1: line 1581 at , : line 5 TenantId: digitechold.onmicrosoft.com

gaborenok avatar Aug 12 '25 14:08 gaborenok

Sorry, I was using only graph permissions, not SharePoint permissions. Solved! Thank you!

gaborenok avatar Aug 12 '25 14:08 gaborenok

Hello, I have another issue. Sorry for not opening another ticket; if it is required, please let me know.

When exporting SCDLPCompliancePolicy with a certificate, I am running into this issue. I have the latest DSC version, and all the dependencies are up to date.

Thanks!


Export-M365DSCConfiguration -Components @("SCDLPCompliancePolicy") -ApplicationId $ApplicationId -CertificateThumbprint $ApplicationSecret -TenantId $TenantId

Error: [2025/08/12 06:01:02] {ObjectNotFound} System.Management.Automation.CommandNotFoundException: The term 'Get-DLPCompliancePolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) "Error during Export:" at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\DSCResources\MSFT_SCDLPCompliancePolicy\MSFT_SCDLPCompliancePolicy.psm1: line 958 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCReverse.psm1: line 680 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.806.1\Modules\M365DSCUtil.psm1: line 1581 at , : line 5 TenantId: digitechold.onmicrosoft.com

gaborenok avatar Aug 12 '25 16:08 gaborenok

@gaborenok Please open dedicated new issues for things not related to the original problem. This helps us distinguishing between multiple problems and adressing them separately.

Anyway, the cmdlet Get-DLPCompliancePolicy is only available if you assign the application the role Security Reader (for reading) or Compliance Administrator (for read / write). Additionally, in the Office 365 Exchange Online permission group, you have to assign Exchange.ManageAsApp.

Image Image

FabienTschanz avatar Aug 12 '25 20:08 FabienTschanz

@FabienTschanz thank you for the support! I will open a new issue next time!

gaborenok avatar Aug 13 '25 09:08 gaborenok