Comments (7)
I found this small query
(Get-Command New-NetNat).Parameters['InternalIPInterfaceAddressPrefix']
over on StackOverflow
Ooh this is great, nice find! Relying on Get-Help
was probably always a bad idea. 😄
Unfortunately, that command returns 0
whether or not the parameter exists, but this seems to do the trick.
if ((Get-Command New-NetNat).Parameters.ContainsKey('InternalIPInterfaceAddressPrefix')) { exit 0 } else { exit 1 }
Would you be willing to test it for me before I make a new release? I've pushed the change to fix/62. I can also generate a build for you, but it sounds like you know how to do that. 😊
from wgserverforwindows.
Looks good to me. The fallback works as expected and should make the support check much more robust.
from wgserverforwindows.
Hey @Dola-Shuvi! Thanks so much for taking the time to report this issue and write a potential fix.
I am a bit hesitant to make changes with side-effects just to perform a test. What if the remove fails? Now the user has testnat
on their system forever. It may also clobber the 172.22.0.0/24
subnet, if that's already configured on the user's system.
I think the more interesting question is why Get-Help
fails on your system, despite your version of New-NetNat
clearly supporting the InternalIPInterfaceAddressPrefix
parameter.
I did some testing and found that, somehow, downloading the help files makes things worse! Check this out.
PS C:\Windows\system32> Get-Help New-NetNat -Parameter InternalIPInterfaceAddressPrefix
-InternalIPInterfaceAddressPrefix <string>
Required? false
Position? Named
Accept pipeline input? false
Parameter set name cim:CreateInstance0
Aliases None
Dynamic? false
PS C:\Windows\system32> update-help netnat
PS C:\Windows\system32> Get-Help New-NetNat -Parameter InternalIPInterfaceAddressPrefix
Get-Help : No parameter matches criteria InternalIPInterfaceAddressPrefix.
At line:1 char:1
+ Get-Help New-NetNat -Parameter InternalIPInterfaceAddressPrefix
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.Manageme...CommandHelpInfo:ProviderCommandHelpInfo) [Get-Help],
PSArgumentException
+ FullyQualifiedErrorId : NoParmsFound,Microsoft.PowerShell.Commands.GetHelpCommand
It may also be related to this issue with German systems.
Would you be willing to try a few more things?
- I wonder if
Get-Help New-NetNat -Parameter *
would work. If so, we could run that and simply check the output forInternalIPInterfaceAddressPrefix
. - Maybe just run
New-NetNat -InternalIPInterfaceAddressPrefix
and ensure the output hasMissing an argument for parameter 'InternalIPInterfaceAddressPrefix'
. I assume if the parameter doesn't exist on the version of Windows, the output would be different (we'd need to verify). - Maybe there some other version (cmdlet, Windows) that would tell us with certainty whether the parameter exists. To be honest, I don't remember when it doesn't, but I definitely ran a test where the command existed and the parameter didn't, which is why I added that extra check.
Let me know what you think.
from wgserverforwindows.
Thanks for the quick response. I am aware that creating a whole subnet is a suboptimal solution and it was more of a temporary fix for myself.
I do not believe this to be caused by the German version of Windows, the Get-Help cmdlet with the -Online parameter works fine on my system.
Get-Help New-NetNat -Parameter *
runs without an error but is also missing the InternalIPInterfaceAddressPrefix
in the help output so checking for it likely wouldn't work. Running this on one of my Windows VMs does contain 'InternalIPInterfaceAddressPrefix' in the help. Running Update-Help netnat
on the VM breaks this however, so its definitely caused by updated help files.
New-NetNat -InternalIPInterfaceAddressPrefix
throws the expected Missing an argument for parameter 'InternalIPInterfaceAddressPrefix'
on my system, but it is localized. Handling all the different localizations of this could be very hard.
I found this small query (Get-Command New-NetNat).Parameters['InternalIPInterfaceAddressPrefix']
over on StackOverflow and it seems to work correctly even when Get-Help
doesn't. I'm not sure on how to check the output for a specific string as I rarely use powershell.
from wgserverforwindows.
Looks like your script is working flawlessly. It exits with 0 if it finds the parameter and exits with 1 if I provide random text as the parameter name. I was about to push a version with some awful string parsing myself so I'm glad you figured out a more elegant approach. Ideally we should also keep the old support check as a fallback in case some system configurations don't work with this change.
from wgserverforwindows.
Ideally we should also keep the old support check as a fallback
Good point! Would be willing to take a peek at my PR #63?
from wgserverforwindows.
Fixed in v2.0.3.
from wgserverforwindows.
Related Issues (20)
- Not working on 32bit Windows
- I'm so amazed I don't know what to say, this is god like. I want to donate HOT 2
- Enable Internet Sharing: An event was unable to invoke any of the subscribers (0x80040201) HOT 1
- Enable configuration of PersistentKeepalive in client configuration HOT 7
- It closes by itself after a while of not using it (Win11). HOT 3
- [Feature Request] Add a removal tool incase the tunnel is incorrectly installed HOT 4
- My server does not have NAT related functions here HOT 2
- [Feature Request] Server MTU Size setting
- route wireguard server hosts file HOT 1
- error
- What's the difference between clients_data/ and clients_wg/ directories? HOT 1
- Invalid class error after splash [already solved] HOT 2
- Client Connection HOT 1
- Enable NAT Failed
- Server keeps trying to handshake after client disconnects HOT 1
- No Internet HOT 2
- Installer does nothing on w2k16 server HOT 1
- Logging or CLI client status HOT 1
- Manually change MTU and restart the service HOT 1
- wgServerforWindows How to uninstall it? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wgserverforwindows.