Remove-UrlAcl.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
Function Remove-UrlAcl {
    [CmdletBinding()] 
    Param( 
        [Parameter(Position=0, ValueFromPipeline=$true)]
        [UrlAcl[]]$UrlAcl
    )

    if($UrlAcl -isnot [System.Array]){
        $UrlAcl = @($UrlAcl)
    }

    $baseCmd = "netsh http delete urlacl"

    foreach($acl in $UrlAcl){
        $deleteCmd = "$baseCmd url=$($acl.Url)"

        $result = Invoke-Expression $deleteCmd

        if($result[1].Trim() -ne "URL reservation successfully deleted"){
            $failMessage = [string]::Join(". ", ($resultFailed | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }))

            throw "Failed to run command $deleteCmd. $failMessage"
        }

        Write-Verbose "Successfully deleted: $($acl.Url)"
    }
}