Public/Uninstall-WacExtension.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
<#
#> Function Uninstall-WacExtension { [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')] param ( [Parameter(Mandatory = $true)] [String] $GatewayEndpoint, [Parameter(Mandatory = $true)] [String] $ExtensionId, [Parameter()] [String] $Version, [Parameter()] [PSCredential] $Credential ) if ($PSCmdlet.ShouldProcess("Uninstall WAC extension ${extensionId}?")) { # Check if extension is in the installed list Write-Verbose -Message 'Getting installed WAC extensions ...' $extension = Get-WacExtension -GatewayEndpoint $GatewayEndpoint -Status Installed -ExtensionId $ExtensionId | Select-Object id, @{l='version';e={[System.Version]$_.version}} | Sort-Object -Property Version if ($extension) { #If version is specified check if it exists in the installed extension list if ($Version) { if ($extension.version -contains $Version) { $extensionVersion = $Version } else { throw "${extensionId} with specified version ${version} is not installed" } } else { #if version is not specified, get the most recent version from the available list $extensionVersion = $extension[0].version.toString() } $params = @{ GatewayEndpoint = $GatewayEndpoint APIEndpoint = "/api/extensions/$($extensionId)/versions/$($extensionVersion)/uninstall" Method = 'Post' } if ($Credential) { $params.Add('Credential',$Credential) } Write-Verbose -Message 'Generating request parameters ...' $requestParameters = Get-RequestParameter @params Write-Verbose -Message 'Invoking uninstall WAC extension api ...' $response = Invoke-WebRequest @requestParameters if ($response.StatusCode -eq 200) { $getParams = @{ GatewayEndpoint = $GatewayEndpoint extensionId = $ExtensionId Status = 'Available' } if ($Credential) { $getParams.Add('Credential', $Credential) } return (Get-WacExtension @getParams) } else { throw 'Error invoking install WAC extension api ...' } } else { throw ("{0} is not installed" -f $ExtensionId) } } } |