We’re seeing a lot of this code in our automation scripts:
if( -not (netsh http show urlacl url=$serviceUrl | Where-Object { $_ -match [regex]::Escape($serviceUrl) }) )
{
Write-Verbose -Message ('Granting {0} permission to listen on {1}.' -f $serviceUser,$serviceUrl) -Verbose
netsh http add urlacl url=$serviceUrl user=$serviceUser delegate=yes | Write-Verbose -Verbose
}
This works. Kind of. It will subtly fail if any user besides $serviceUser
has permission to $serviceUrl
. So far, this hasn’t bitten us, but it might.
I’d like to create a function, Grant-HttpUrlPermission, that uses the HTTP Server API to handle and abstract this stuff out, but only if it doesn’t already exist.
So, is there a PowerShell equivalent to the netsh http
commands that will work on both Windows 7 and Windows 2012 R2?