The Add-MgApplicationPassword
cmdlet is a Microsoft Graph PowerShell command used to add a password credential to an application. This is particularly useful for managing app registrations and ensuring secure authentication for applications in Azure AD.
Add-MgApplicationPassword -ApplicationId <String> -PasswordCredential <Hashtable>
displayName
, startDateTime
, and endDateTime
.This example adds a password credential to an application that expires in six months.
# Connect to Microsoft Graph with the required permissions
Connect-MgGraph -Scopes 'Application.ReadWrite.All'
# Define the application object ID
$appObjectId = 'eaf1e531-0d58-4874-babe-b9a9f436e6c3'
# Define the password credential details
$passwordCred = @{
displayName = 'Created in PowerShell'
endDateTime = (Get-Date).AddMonths(6)
}
# Add the password credential
$secret = Add-MgApplicationPassword -ApplicationId $appObjectId -PasswordCredential $passwordCred
# Display the details of the created secret
$secret | Format-List
This example sets both a start and end date for the password credential
# Connect to Microsoft Graph with the required permissions
Connect-MgGraph -Scopes 'Application.ReadWrite.All'
# Define the application object ID
$appObjectId = 'eaf1e531-0d58-4874-babe-b9a9f436e6c3'
# Define the start and end dates
$startDate = (Get-Date).AddDays(1).Date
$endDate = $startDate.AddMonths(6)
# Define the password credential details
$passwordCred = @{
displayName = 'Created in PowerShell'
startDateTime = $startDate
endDateTime = $endDate
}
# Add the password credential
$secret = Add-MgApplicationPassword -ApplicationId $appObjectId -PasswordCredential $passwordCred
# Display the details of the created secret
$secret | Format-List
Application.ReadWrite.All
, when using this cmdlet.endDateTime
property to define a valid expiry date for the credential. This improves security by enforcing rotation.Error | Cause | Solution |
Insufficient privileges to complete the operation | The account used does not have the Application.ReadWrite.All permission | Assign the required permission and re-authenticate with Connect-MgGraph. |
Invalid Application ID | The provided application ID is incorrect or does not exist. | Verify the application ID in Azure AD and retry the cmdlet. |
PasswordCredential property is null or invalid | The hashtable passed to the -PasswordCredential parameter is malformed. | Ensure the hashtable includes valid keys such as displayName, endDateTime, and optionally startDateTime. |
Value cannot be null. Parameter name: endDateTime | The endDateTime value was not provided in the -PasswordCredential parameter. | Specify a valid endDateTime value in the hashtable. |
The Add-MgApplicationPassword cmdlet simplifies the process of managing password credentials for Azure AD applications, offering flexibility and security. By adhering to best practices and addressing common errors, administrators can seamlessly integrate this cmdlet into their workflows for secure and efficient application management.
© m365corner.com. All Rights Reserved. Design by HTML Codex