-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authentication via Application-Permission #52
Comments
By playing around with the type-parameter, I was possible to export a few entities. I do like the idea of this script a lot. It would be great to have those enhancements in the feature or at least some kind of a table in the readme.md, which is illustrates something like this:
An additional suggestion would be to give the user a better hint by proper error-handling. My pipeline just stopped with e.g.:
|
Hello, Best Regards |
@israem what version of powershell are you running this in? |
I ran the module in both PS7 (up tp 7.2.14) and PS5 successfully. I ran the snippet of code I shared in PS7 but there is no reason it wouldn't work in PS5 if you have all the modules installed. |
I see. I've been messing with it all week. Finally figured out that it gives me errors (same as in original post on this issue) in 7.X, but works fine in 5.1. |
Seems like same issue I encountered too #57 |
I'm trying to use a service principal as well to automate the export. It's not working for me this way. I did a lot of tinkering and found the script provided below to work with no errors. The script states that it's Connected via userprovidedaccesstoken access using the ClientID. After script is ran and completed nothing shows in the folder that was created for the backup. I have tried this with a folder that already exists as well and in different drives/ folders. # Define variables
$backupPath = "C:\Backup\EntraBackup\$((Get-Date).ToString('yyyy-MM-dd'))"
$tenantID = 'Tenant ID' # Replace with your actual Tenant ID
$clientID = 'Application (client) ID' # Replace with your Application (client) ID
$clientSecret = 'Application (client) secret' # Replace with your Application (client) secret
# Create backup folder
New-Item -ItemType Directory -Path "$backupPath"
# Scopes required for the backup operation (Microsoft Graph API)
$scopes = @('https://graph.microsoft.com/.default')
# Convert the client secret into a secure string and pass to the New-MsalClientApplication
$secureClientSecret = (ConvertTo-SecureString "$clientSecret" -AsPlainText -Force)
# Install the necessary modules if not already installed
Write-Host 'Installing required modules...'
Install-Module -Name MSAL.PS
Install-Module -Name Microsoft.Graph.Authentication
Install-Module -Name EntraExporter
# Create the MSAL Confidential Client Application (Service Principal Authentication)
Write-Host 'Authenticating using Service Principal...'
$msalApp = New-MsalClientApplication -clientId $clientID -clientSecret $secureClientSecret -Authority "https://login.microsoftonline.com/$tenantID"
# Acquire the token for Microsoft Graph API
Write-Host 'Acquiring token for Microsoft Graph API...'
$tokenResponse = Get-MsalToken -clientID $clientID -clientSecret $secureClientSecret -tenantID $tenantID -Scopes $scopes
# Extract the access token from the response
$graphToken = (ConvertTo-SecureString $tokenResponse.AccessToken -AsPlainText -Force)
# Check if the token was retrieved successfully
if (-not $graphToken) {
Write-Host "Failed to obtain access token. Exiting script."
exit
}
Write-Host "Successfully authenticated. Access Token acquired."
# Connect to Microsoft Graph using the acquired token
Write-Host 'Connecting to Microsoft Graph...'
Connect-MgGraph -AccessToken $graphToken
# Connect to Entra ID and perform a full export
Write-Host 'Connecting to Entra ID...'
# Start the backup process
Write-Host 'Starting backup...'
Export-Entra -Path "$backupPath" -All
Write-Host 'Backup complete...' |
Hello Everyone
I set up the pipeline with a Service-Principal, for which all the relevant API-Permissions have been consented.
Additionally I use
Connect-MgGraph -TenantId $tenantId -ClientSecretCredential $clientSecretCredential
to be able to authenticate properly with clientid and clientsecret.I made sure that the app has the sufficient privileges by running
Get-MgContext | Select-Object -ExpandProperty Scopes
After that I run
Export-Entra $path -All
, but receive the following outputLong story short:
Is it possible to use this script with application-based permissions?
The text was updated successfully, but these errors were encountered: