Create Pull Request
| Date | Scan | Status | Result |
|---|---|---|---|
| 2026-01-14 00:00 | #250 | in_progress |
Biased
|
| 2026-01-13 00:00 | #246 | completed |
Biased
|
| 2026-01-12 00:00 | #243 | cancelled |
Biased
|
| 2026-01-11 00:00 | #240 | completed |
Biased
|
| 2026-01-10 00:00 | #237 | completed |
Biased
|
| 2026-01-09 00:34 | #234 | completed |
Biased
|
| 2026-01-08 00:53 | #231 | completed |
Biased
|
| 2026-01-06 18:15 | #225 | cancelled |
Clean
|
| 2025-08-17 00:01 | #83 | cancelled |
Clean
|
| 2025-07-13 21:37 | #48 | completed |
Biased
|
| 2025-07-09 13:09 | #3 | cancelled |
Clean
|
| 2025-07-08 04:23 | #2 | cancelled |
Biased
|
param
(
[Parameter(Mandatory=$true, HelpMessage="Enter Azure subscription name - you need to be subscription admin to execute the script")]
[string] $subscriptionName,
[Parameter(Mandatory=$false, HelpMessage="Provide SPN role assignment")]
[string] $spnRole = "owner",
[Parameter(Mandatory=$false, HelpMessage="Provide Azure environment name for your subscription")]
[string] $environmentName = "AzureUSGovernment"
)
# Initialize
$ErrorActionPreference = "Stop"
$VerbosePreference = "SilentlyContinue"
$userName = ($env:USERNAME).Replace(' ', '')
$newguid = [guid]::NewGuid()
$displayName = [String]::Format("AzDevOps.{0}.{1}", $userName, $newguid)
$homePage = "http://" + $displayName
$identifierUri = $homePage
# Check for Azure Az PowerShell module
$isAzureModulePresent = Get-Module -Name Az -ListAvailable
if ([String]::IsNullOrEmpty($isAzureModulePresent) -eq $true)
{
Write-Output "Script requires Azure PowerShell modules to be present. Obtain Azure PowerShell from https://learn.microsoft.com//powershell/azure/install-az-ps" -Verbose
return
}
Import-Module -Name Az.Accounts
Write-Output "Provide your credentials to access your Azure subscription $subscriptionName" -Verbose
Connect-AzAccount -Subscription $subscriptionName -Environment $environmentName
$azureSubscription = Get-AzSubscription -SubscriptionName $subscriptionName
$connectionName = $azureSubscription.Name
$tenantId = $azureSubscription.TenantId
$id = $azureSubscription.SubscriptionId
# Create new Azure AD application
Write-Output "Creating new application in Azure AD (App URI - $identifierUri)" -Verbose
$azureAdApplication = New-AzADApplication -DisplayName $displayName -HomePage $homePage -Verbose
$appId = $azureAdApplication.AppId
$objectId = $azureAdApplication.Id
Write-Output "Azure AD application creation completed successfully (Application Id: $appId) and (Object Id: $objectId)" -Verbose
# Add secret to Azure AD application
Write-Output "Creating new secret for Azure AD application"
$secret = New-AzADAppCredential -ObjectId $objectId -EndDate (Get-Date).AddYears(2)
Write-Output "Secret created successfully" -Verbose
# Create new SPN
Write-Output "Creating new SPN" -Verbose
$spn = New-AzADServicePrincipal -ApplicationId $appId
$spnName = $spn.DisplayName
Write-Output "SPN creation completed successfully (SPN Name: $spnName)" -Verbose
# Assign role to SPN
Write-Output "Waiting for SPN creation to reflect in directory before role assignment"
Start-Sleep 20
Write-Output "Assigning role ($spnRole) to SPN app ($appId)" -Verbose
New-AzRoleAssignment -RoleDefinitionName $spnRole -ApplicationId $spn.AppId
Write-Output "SPN role assignment completed successfully" -Verbose
# Print values
Write-Output "`nCopy and paste below values for service connection" -Verbose
Write-Output "***************************************************************************"
Write-Output "Connection Name: $connectionName(SPN)"
Write-Output "Environment: $environmentName"
Write-Output "Subscription Id: $id"
Write-Output "Subscription Name: $connectionName"
Write-Output "Service Principal Id: $appId"
Write-Output "Tenant Id: $tenantId"
Write-Output "***************************************************************************"