PoshWSUS icon indicating copy to clipboard operation
PoshWSUS copied to clipboard

Incorrect handling server names from registry

Open MVKozlov opened this issue 8 years ago • 3 comments

  • Currently, server names with '-' not supported
  • Absent port from registry not supported (no default to 80)
  • Canonical url (ended with '/') not supported

My suggestions: If ((Get-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate -Name WUServer).WUServer -match '(?<Protocol>^http(s)?)(?:://)(?<Computername>(?:(?:[\w-]+(?:\.)?)+))(?::)?(?<Port>\d*)/?') { $WsusServer = $Matches.Computername; if ($Matches.Port) { $Port = $Matches.Port } } Slightly corrected regex and test for empty port. btw, isn't a time to correct default port to 8530 ?

sorry for formatting. cant get it as need

MVKozlov avatar Apr 04 '16 10:04 MVKozlov

I'm assuming that this all refers to Connect-PSWSUSServer...correct? At this point in time, you are correct that we can move the default port to 8530 and good catch on server names with a '-' in them. Good things to look at improving on with the next release.

proxb avatar Apr 04 '16 23:04 proxb

Definitely, I'm talking about Connect-PSWSUSServer :)

btw, take into account that if default server port will be changed to 8530, than my code above need addition if ($Matches.Port) { $Port = $Matches.Port } else { $Port = 80 } #because default url without port equal to port=80

MVKozlov avatar Apr 05 '16 07:04 MVKozlov

I'm still learning how Git-Hub works and how to contribute.... but there was a bug where the registry name was an alias that gave a fit when I tried connecting to it. I got around this by doing a DNS lookup. It would resolve and output the FQDN. Perhaps if your regex included everything between the first "//" and the last ":" and did a look up, it wouldn't matter? Still learning regex too, so not sure how that would work. Also not sure if all entries have a port...

What I use: $WsusServer = [System.Net.DNS]::GetHostEntry("$WsusServer").hostname

The gethostentry has an address list as well which you could cycle through to get around any name or alias. Could try/cycle the port too.

TaylorWhitt avatar Sep 04 '16 10:09 TaylorWhitt