Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joerodgers/b1cd5d65a0f748eb866b3db02bd8dba8 to your computer and use it in GitHub Desktop.
Save joerodgers/b1cd5d65a0f748eb866b3db02bd8dba8 to your computer and use it in GitHub Desktop.
#requires -modules "AzureAD"
Connect-AzureAD
$clientId = 'aa326a3b-706a-4a7c-a96f-1a7e371e967x'
$endDate = [DateTime]::Today.AddYears(2)
$startDate = [Datetime]::Today
$app = Get-AzureADServicePrincipal -Filter "AppId eq '$clientId'"
$base64secret = New-AzureADServicePrincipalPasswordCredential -ObjectId $app.ObjectId -EndDate $endDate
$null = New-AzureADServicePrincipalKeyCredential -ObjectId $app.ObjectId -StartDate $startDate -EndDate $endDate -Type Symmetric -Usage Verify -Value $base64secret.Value
$null = New-AzureADServicePrincipalKeyCredential -ObjectId $app.ObjectId -StartDate $startDate -EndDate $endDate -Type Symmetric -Usage Sign -Value $base64secret.Value
[PSCustomObject] @{
ClientId = $clientId
Secret = [Convert]::ToBase64String( [System.Text.Encoding]::UTF8.GetBytes($base64secret.Value) )
StartDate = $startDate
EndDate = $endDate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment