-
Notifications
You must be signed in to change notification settings - Fork 250
Entra ID application provisioning and user re‐enablement
This page documents the PowerShell script eid-resetapp-set-direct.ps1, which provisions or updates an Entra ID application, adds a secret, ensures the service principal exists, assigns application permissions, and can optionally re-enable a user through Microsoft Graph.
The script uses Microsoft Graph directly via the Microsoft Graph PowerShell SDK and does not depend on Azure CLI.
The script is designed for administrators who need a production-friendly, low-dependency method to:
- create or update an Entra application registration
- add a client secret for app authentication
- ensure the application has a service principal
- assign Microsoft Graph application permissions
- generate an admin-consent URL for tenant-wide approval
- optionally re-enable a user account by UPN or object ID
- optionally run in app-only recovery mode without a delegated user sign-in
Before running the script, confirm the following:
- PowerShell 7 or later is installed.
- The Microsoft Graph PowerShell authentication module is available:
Install-Module Microsoft.Graph.Authentication -Scope CurrentUser
- The account running the script has sufficient permissions to:
- create or update applications
- create or update service principals
- assign Graph application permissions
- re-enable a user account when required
When run without the app-only switch, the script:
- connects to Microsoft Graph using an interactive device-code sign-in
- looks for an existing application with the requested display name
- creates or updates the application registration
- adds a client secret
- ensures a service principal exists
- updates the application with the required Graph permissions
- builds an admin-consent URL
- optionally re-enables a user account
When run with -AppOnly, the script uses the supplied application credentials to connect to Microsoft Graph without a delegated user login. This is intended for recovery scenarios where a break-glass application is used to re-enable a user account.
| Parameter | Description |
|---|---|
-AppName |
Display name for the application to create or update. Defaults to Reset-Operations-App if not supplied. |
-Force |
Skips confirmation prompts and runs non-interactively. |
-SkipConsentUrl |
Prevents copying the consent URL to the clipboard. |
-TenantId |
Tenant ID to target. Defaults to organizations for interactive tenant selection. |
-UserPrincipalName |
User principal name of the account to re-enable. |
-UserObjectId |
Object ID of the account to re-enable. |
-ReEnableUser |
Enables the user re-enable operation after provisioning or recovery setup. |
-AppOnly |
Uses app-based authentication instead of interactive sign-in. |
-ClientId |
Client ID of the app used for app-only authentication. |
-ClientSecret |
Client secret for the app used for app-only authentication. |
-CertificateThumbprint |
Certificate thumbprint to use for certificate-based app-only authentication. |
-CertificatePath |
Path to a certificate file to use for certificate-based app-only authentication. |
. .\eid-resetapp-set-direct.ps1 -AppName "Reset-Operations-App" -Force. .\eid-resetapp-set-direct.ps1 `
-AppName "Reset-Operations-App" `
-TenantId "<tenant-id>" `
-ReEnableUser `
-UserPrincipalName "director@contoso.com". .\eid-resetapp-set-direct.ps1 `
-AppOnly `
-ClientId "<app-client-id>" `
-ClientSecret "<client-secret>" `
-TenantId "<tenant-id>" `
-ReEnableUser `
-UserPrincipalName "director@contoso.com". .\eid-resetapp-set-direct.ps1 `
-AppOnly `
-ClientId "<app-client-id>" `
-CertificateThumbprint "<thumbprint>" `
-TenantId "<tenant-id>" `
-ReEnableUser `
-UserObjectId "<user-object-id>"The script assigns the following Microsoft Graph application permissions:
User.EnableDisableAccount.AllDirectory.ReadWrite.AllUser.ReadWrite.All
These are broad administrator-level permissions and should be reviewed carefully before use in a production environment.
After the script creates or updates the application, it displays a consent URL. The URL can be copied to the clipboard and opened in a browser so a tenant administrator can grant consent.
- Use this script only in a controlled and approved administrative context.
- Store secrets securely and avoid hard-coding credentials into scripts or documentation.
- Prefer certificate-based authentication for production if available.
- Review the application permissions carefully before granting consent.
- App-only recovery mode should be limited to approved break-glass scenarios.
- The script uses direct REST calls to Microsoft Graph rather than relying on Azure CLI.
- The script is intended to be idempotent: running it again will update the existing application instead of creating duplicate objects.
- In app-only mode, the script skips the provisioning flow and focuses on the recovery workflow.
The script prints a summary that includes:
- the operation status
- the tenant ID
- the application object ID
- the application client ID
- the app secret (when created)
- the service principal ID
- the consent URL
- the re-enabled user identity when applicable