generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Remove-AzApiManagementUser script (#321)
* added Remove-AzApiManagementUser script * fix create user docs * added docs for Remove-AzApiManagementUser * renamed scripts to prevent issues Co-authored-by: Pim Simons <[email protected]>
- Loading branch information
1 parent
bd26e41
commit 2c31e34
Showing
7 changed files
with
243 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+100 Bytes
(100%)
src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psd1
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
40 changes: 40 additions & 0 deletions
40
src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUserAccount.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
param( | ||
[string][Parameter(Mandatory = $true)] $ResourceGroupName = $(throw "Resource group name is required"), | ||
[string][parameter(Mandatory = $true)] $ServiceName = $(throw "API management service name is required"), | ||
[string][parameter(Mandatory = $true)] $MailAddress = $(throw "The mail-address of the user is required"), | ||
[string][parameter(Mandatory = $false)] $SubscriptionId, | ||
[string][parameter(Mandatory = $false)] $AccessToken | ||
) | ||
|
||
$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName | ||
if ($apim -eq $null) { | ||
throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" | ||
} | ||
$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName | ||
|
||
if ($SubscriptionId -eq "" -or $AccessToken -eq "") { | ||
# Request accessToken in case the script contains no records | ||
$token = Get-AzCachedAccessToken | ||
|
||
$AccessToken = $token.AccessToken | ||
$SubscriptionId = $token.SubscriptionId | ||
} | ||
|
||
try { | ||
Write-Host "Retrieving the user account with e-mail '$mailAddress'" | ||
$apimUser = Get-AzApiManagementUser -Context $apimContext -Email $MailAddress | ||
|
||
if ($apimUser -ne $null) { | ||
$apimUserId = $apimUser.UserId | ||
|
||
Write-Host "Attempting to remove the user account with e-mail '$mailAddress' and id '$apimUserId'" | ||
Remove-AzApiManagementUser -Context $apimContext -UserId $apimUserId | ||
Write-Host "Removed the user account with e-mail '$mailAddress' and id '$apimUserId'" | ||
} else { | ||
Write-Host "User account with e-mail '$mailAddress' not found in the APIM instance '$ServiceName'" | ||
} | ||
} | ||
catch { | ||
Write-Host $_ | ||
throw "Failed to remove the user account for '$MailAddress' in the APIM instance '$ServiceName'" | ||
} |
Oops, something went wrong.