Code Monkey home page Code Monkey logo

Comments (7)

micahmo avatar micahmo commented on July 27, 2024 1

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.

Dola-Shuvi avatar Dola-Shuvi commented on July 27, 2024 1

Looks good to me. The fallback works as expected and should make the support check much more robust.

from wgserverforwindows.

micahmo avatar micahmo commented on July 27, 2024

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 for InternalIPInterfaceAddressPrefix.
  • Maybe just run New-NetNat -InternalIPInterfaceAddressPrefix and ensure the output has Missing 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.

Dola-Shuvi avatar Dola-Shuvi commented on July 27, 2024

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.

Dola-Shuvi avatar Dola-Shuvi commented on July 27, 2024

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.

micahmo avatar micahmo commented on July 27, 2024

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.

micahmo avatar micahmo commented on July 27, 2024

Fixed in v2.0.3.

from wgserverforwindows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.