Connect-AzureAD
is deprecated, but so is the entire MSOnline
module (which includes Get-MsolServicePrincipal
and New-MsolServicePrincipalCredential
). These cmdlets should be replaced with Microsoft Graph PowerShell equivalents. The caveat is that Microsoft has not provided 1-to-1 replacements for all MSOnline
cmdlets yet — especially Get-MsolServicePrincipalCredential
and New-MsolServicePrincipalCredential
. So, you'll need to work within the supported tooling using Microsoft Graph PowerShell SDK, which connects via Connect-MgGraph
.
- Install Microsoft Graph PowerShell, if not already installed:
Install-Module Microsoft.Graph -Scope CurrentUser
Then import the module:
Import-Module Microsoft.Graph
- Connect to Microsoft Entra ID
Connect-MgGraph -Scopes "Application.Read.All", "Application.ReadWrite.All"
You’ll need to consent to permissions. These can be delegated or app-based.
- List all applications (service principals)
$appList = Get-MgServicePrincipal -All | Where-Object {
$_.DisplayName -notlike "*Microsoft*" -and
$_.DisplayName -notlike "autohost*" -and
$_.ServicePrincipalNames -notlike "*localhost*"
}
- List app credentials (App Secrets / Certificates)
foreach ($app in $appList) {
$creds = Get-MgServicePrincipal -ServicePrincipalId $app.Id |
Select-Object -ExpandProperty PasswordCredentials
foreach ($cred in $creds) {
"$($app.DisplayName);$($app.AppId);$($cred.KeyId);$($cred.StartDateTime);$($cred.EndDateTime)" |
Out-File -FilePath "C:\temp\output.txt" -Append
}
}
If there are certificates (not just secrets), use KeyCredentials
property instead of PasswordCredentials
.
- Add a new client secret
To generate and add a new password credential:
$clientId = "12345asd-avf5-hy78-asd5-9a71fa0a4024"
$bytes = New-Object byte[] 32
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
$newClientSecret = [Convert]::ToBase64String($bytes)
$params = @{
PasswordCredential = @{
DisplayName = "Auto-generated secret"
EndDateTime = (Get-Date).AddYears(1).ToString("o")
StartDateTime = (Get-Date).ToString("o")
SecretText = $newClientSecret
}
}
# This is for an Application (not ServicePrincipal)
Add-MgApplicationPassword -ApplicationId $clientId -BodyParameter $params.PasswordCredential
# Output the secret for use
$newClientSecret
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin