Skip to content

Commit 358e4d8

Browse files
committed
bug fix for remove app/sp credential
1 parent 29adb87 commit 358e4d8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Resources/MSGraph.Autorest/custom/Remove-AzAdAppCredential.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function Remove-AzAdAppCredential {
134134
} else {
135135
$list = @()
136136
foreach ($key in $app.KeyCredentials) {
137-
if (!$key.KeyId.Equals($PSBoundParameters['KeyId'])) {
137+
if ($PSBoundParameters['KeyId'] -ne $key.KeyId) {
138138
$list += $key
139139
}
140140
}
@@ -143,16 +143,20 @@ function Remove-AzAdAppCredential {
143143
$PSBoundParameters['Id'] = $app.Id
144144
$PSBoundParameters['KeyCredentials'] = $list
145145
MSGraph.internal\Update-AzAdApplication @PSBoundParameters
146+
$foundKey = $true
146147
} else {
147148
foreach ($password in $app.PasswordCredentials) {
148-
if ($password.KeyId.Equals($PSBoundParameters['KeyId'])) {
149+
if ($PSBoundParameters['KeyId'] -eq $password.KeyId) {
149150
$PSBoundParameters['ApplicationId'] = $app.Id
150151
MSGraph.internal\Remove-AzAdApplicationPassword @PSBoundParameters
152+
$foundKey = $true
151153
break
152154
}
153155
}
154156
}
155-
Write-Error "application '$($app.Id)' does not contains credential with key id: '$($PSBoundParameters['KeyId'])'."
157+
if (!$foundKey) {
158+
Write-Error "application '$($app.Id)' does not contains credential with key id: '$($PSBoundParameters['KeyId'])'."
159+
}
156160
}
157161
if ($PSBoundParameters['PassThru']) {
158162
$PSCmdlet.WriteObject($true)

src/Resources/MSGraph.Autorest/custom/Remove-AzAdSpCredential.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function Remove-AzAdSpCredential {
134134
} else {
135135
$list = @()
136136
foreach ($key in $sp.KeyCredentials) {
137-
if (!$key.KeyId.Equals($PSBoundParameters['KeyId'])) {
137+
if ($PSBoundParameters['KeyId'] -ne $key.KeyId) {
138138
$list += $key
139139
}
140140
}
@@ -143,16 +143,20 @@ function Remove-AzAdSpCredential {
143143
$PSBoundParameters['Id'] = $sp.Id
144144
$PSBoundParameters['KeyCredentials'] = $list
145145
MSGraph.internal\Update-AzAdServicePrincipal @PSBoundParameters
146+
$foundKey = $true
146147
} else {
147148
foreach ($password in $sp.PasswordCredentials) {
148-
if ($password.KeyId.Equals($PSBoundParameters['KeyId'])) {
149+
if ($PSBoundParameters['KeyId'] -eq $password.KeyId) {
149150
$PSBoundParameters['ServicePrincipalId'] = $sp.Id
150151
MSGraph.internal\Remove-AzAdServicePrincipalPassword @PSBoundParameters
152+
$foundKey = $true
151153
break
152154
}
153155
}
154156
}
155-
Write-Error "service principal '$($sp.Id)' does not contains credential with key id: '$($PSBoundParameters['KeyId'])'."
157+
if (!$foundKey) {
158+
Write-Error "service principal '$($sp.Id)' does not contains credential with key id: '$($PSBoundParameters['KeyId'])'."
159+
}
156160
if ($PSBoundParameters['PassThru']) {
157161
$PSCmdlet.WriteObject($true)
158162
}

0 commit comments

Comments
 (0)