Created
December 1, 2023 07:00
-
-
Save jakenuts/b80a83919f01afb0e8995f9ae7d5cde4 to your computer and use it in GitHub Desktop.
A powershell script that calls 'netsh http show urlacl' and formats the url, user, listen and deletgate fields into a table.
This file contains hidden or 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
# Function to parse the 'netsh http show urlacl' output and format it into a table | |
function Format-UrlAcl { | |
# Execute the 'netsh http show urnetsh http show urlacllacl' command | |
$urlAclOutput = | |
# Initialize an array to store the formatted objects | |
$formattedOutput = @() | |
# Split the output into lines | |
$lines = $urlAclOutput -split " | |
? | |
" | |
# Variables to hold current URL, User, Listen, and Delegate | |
$currentUrl = $null | |
$currentUser = $null | |
$currentListen = $null | |
$currentDelegate = $null | |
foreach ($line in $lines) { | |
if ($line -match "Reserved URL\s+:\s+(.*)") { | |
# When a new URL is found, process the previous user (if any) | |
if ($currentUser -ne $null) { | |
$formattedOutput += [PSCustomObject]@{ | |
URL = $currentUrl | |
User = $currentUser | |
Listen = $currentListen | |
Delegate = $currentDelegate | |
} | |
} | |
# Update current URL and reset other fields | |
$currentUrl = $matches[1] | |
$currentUser = $null | |
$currentListen = $null | |
$currentDelegate = $null | |
} | |
elseif ($line -match "User:\s+(.*)") { | |
$currentUser = $matches[1] | |
} | |
elseif ($line -match "Listen:\s+(\w+)") { | |
$currentListen = $matches[1] | |
} | |
elseif ($line -match "Delegate:\s+(\w+)") { | |
$currentDelegate = $matches[1] | |
} | |
} | |
# Add the last user (if any) | |
if ($currentUser -ne $null) { | |
$formattedOutput += [PSCustomObject]@{ | |
URL = $currentUrl | |
User = $currentUser | |
Listen = $currentListen | |
Delegate = $currentDelegate | |
} | |
} | |
# Return the formatted output as a table | |
return $formattedOutput | Format-Table | |
} | |
# Call the function to format and display the URL ACLs | |
Format-UrlAcl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment