33# Licensed under the MIT License. See License in the project root for license information.
44# ------------------------------------------------------------------------------
55function Remove-EntraBetaUserExtension {
6- [CmdletBinding (DefaultParameterSetName = ' SetSingle ' )]
6+ [CmdletBinding (DefaultParameterSetName = ' RemoveSingle ' )]
77 param (
8- [Parameter (ParameterSetName = " SetSingle" , Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
9- [System.String ] $ExtensionName ,
10-
11- [Alias (' ObjectId' )]
12- [Parameter (ParameterSetName = " SetSingle" , Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
13- [Parameter (ParameterSetName = " SetMultiple" , Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
14- [System.String ] $ExtensionId ,
8+ [Parameter (ParameterSetName = " RemoveMultiple" , Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
9+ [System.Collections.Generic.List ` 1 [System.String ]] $ExtensionNames ,
1510
16- [Parameter (ParameterSetName = " SetMultiple" , Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
17- [System.Collections.Generic.List ` 1 [System.String ]] $ExtensionNames
11+ [Parameter (ParameterSetName = " RemoveSingle" , Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
12+ [System.String ] $ExtensionName ,
13+
14+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
15+ [Alias (' ObjectId' )]
16+ [ValidateNotNullOrEmpty ()]
17+ [ValidateScript ({
18+ if ($_ -match ' ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' -or
19+ $_ -match ' ^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$' ) {
20+ return $true
21+ }
22+ throw " UserId must be a valid email address or GUID."
23+ })]
24+ [System.String ] $UserId
1825 )
1926
2027 begin {
@@ -29,64 +36,30 @@ function Remove-EntraBetaUserExtension {
2936 PROCESS {
3037 $params = @ {}
3138 $customHeaders = New-EntraBetaCustomHeaders - Command $MyInvocation.MyCommand
32-
33- if ($null -ne $PSBoundParameters [" ExtensionName" ]) {
34- $params [" ExtensionName" ] = $PSBoundParameters [" ExtensionName" ]
35- }
36- if ($null -ne $PSBoundParameters [" ProgressAction" ]) {
37- $params [" ProgressAction" ] = $PSBoundParameters [" ProgressAction" ]
38- }
39- if ($PSBoundParameters.ContainsKey (" Debug" )) {
40- $params [" Debug" ] = $PSBoundParameters [" Debug" ]
41- }
42- if ($null -ne $PSBoundParameters [" OutBuffer" ]) {
43- $params [" OutBuffer" ] = $PSBoundParameters [" OutBuffer" ]
44- }
45- if ($null -ne $PSBoundParameters [" ErrorAction" ]) {
46- $params [" ErrorAction" ] = $PSBoundParameters [" ErrorAction" ]
47- }
48- if ($null -ne $PSBoundParameters [" WarningVariable" ]) {
49- $params [" WarningVariable" ] = $PSBoundParameters [" WarningVariable" ]
50- }
51- if ($null -ne $PSBoundParameters [" WarningAction" ]) {
52- $params [" WarningAction" ] = $PSBoundParameters [" WarningAction" ]
53- }
54- if ($null -ne $PSBoundParameters [" ExtensionId" ]) {
55- $params [" ExtensionId" ] = $PSBoundParameters [" ExtensionId" ]
56- }
57- if ($null -ne $PSBoundParameters [" OutVariable" ]) {
58- $params [" OutVariable" ] = $PSBoundParameters [" OutVariable" ]
59- }
60- if ($PSBoundParameters.ContainsKey (" Verbose" )) {
61- $params [" Verbose" ] = $PSBoundParameters [" Verbose" ]
62- }
39+ $body = @ {}
40+
6341 if ($null -ne $PSBoundParameters [" ExtensionNames" ]) {
64- $params [" ExtensionNames" ] = $PSBoundParameters [" ExtensionNames" ]
65- }
66- if ($null -ne $PSBoundParameters [" PipelineVariable" ]) {
67- $params [" PipelineVariable" ] = $PSBoundParameters [" PipelineVariable" ]
68- }
69- if ($null -ne $PSBoundParameters [" InformationVariable" ]) {
70- $params [" InformationVariable" ] = $PSBoundParameters [" InformationVariable" ]
71- }
72- if ($null -ne $PSBoundParameters [" InformationAction" ]) {
73- $params [" InformationAction" ] = $PSBoundParameters [" InformationAction" ]
42+ foreach ($extName in $PSBoundParameters [" ExtensionNames" ]) {
43+ $body [$extName ] = $null
44+ }
7445 }
75- if ($null -ne $PSBoundParameters [" ErrorVariable " ]) {
76- $params [ " ErrorVariable " ] = $PSBoundParameters [ " ErrorVariable " ]
46+ if ($null -ne $PSBoundParameters [" ExtensionName " ]) {
47+ $body [ $PSBoundParameters [ " ExtensionName " ]] = $null
7748 }
7849
50+ # Invoke API call using UserId and ExtensionId
7951 Write-Debug (" ============================ TRANSFORMATIONS ============================" )
8052 $params.Keys | ForEach-Object { " $_ : $ ( $params [$_ ]) " } | Write-Debug
8153 Write-Debug (" =========================================================================`n " )
82-
83- $response = Remove-MgBetaUserExtension @params - Headers $customHeaders
54+
55+ $uri = " /beta/users/$UserId "
56+ $response = Invoke-MgGraphRequest - Method PATCH - Uri $uri - Body $body - Headers $customHeaders
8457 $response | ForEach-Object {
8558 if ($null -ne $_ ) {
86- Add-Member - InputObject $_ - MemberType AliasProperty - Name ObjectId - Value Id
87-
59+ Add-Member - InputObject $_ - MemberType AliasProperty - Name ObjectId - Value UserId
8860 }
8961 }
62+
9063 $response
9164 }
9265}
0 commit comments