How do you discover things like [Net.ServicePointManager]::SecurityProtocol ?

Welcome Forums General PowerShell Q&A How do you discover things like [Net.ServicePointManager]::SecurityProtocol ?

Viewing 6 reply threads
  • Author
    Posts
    • #217380
      Participant
      Topics: 6
      Replies: 18
      Points: 49
      Rank: Member

      One of powershell selling points is discoverability

      I’ve seen this [Net.ServicePointManager]::SecurityProtocol  object and other .Net objects used in many scripts , but it’s not in the powershell docs or i’m just blind.

      So how do people discover things like this , or how do you know you need something like this , do you have to be a .Net developer ?
      I have to say that i don’t know anything about .Net , i have bash , python si some powershell scripting skills but that’s about it when it comes to programming.

    • #217392
      Participant
      Topics: 4
      Replies: 2248
      Points: 5,490
      Helping Hand
      Rank: Community MVP

      Well …. my first thought would be to use my favorite search enginge … 😉

      That would bring up as one of the first hits this: https://docs.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.securityprotocol?view=netframework-4.8

    • #217530
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      It’s not normal practice through Powershell to require manipulation of .NET settings. The [Net.ServicePointManager]::SecurityProtocol is typically used to elevate the TLS\SSL protocol for Invoke-RestMethod as it defaults to 1.0, which is deprecated due to security in many APIs. This causes the “Underlying connection has been closed” errors if you don’t use the correct protocol.

      These are band-aids because that setting is not manipulable via the cmdlet. As you see the everywhere, the developers realized they need be manipulated and were added in later versions. If you look at the documentation, in later versions of Invoke-RestMethod, they added -SslProtocol. Another .NET setting was client callback for skipping certificate checks, which has been added as a parameter -SkipCertificateCheck.

    • #217815
      Participant
      Topics: 6
      Replies: 18
      Points: 49
      Rank: Member

      Thank you Rob , you partially answered my question.
      Do you think that some .Net programming knowledge is required to solve issues with powershell , or just a google/bing search is enough ?

    • #217830
      js
      Participant
      Topics: 29
      Replies: 814
      Points: 2,456
      Helping Hand
      Rank: Community Hero

      You could use tab completion on both the type and method names. You could run the method without the parentheses to see the definition. You can google the type and method name to see the microsoft doc on it.

    • #218184
      Participant
      Topics: 12
      Replies: 1623
      Points: 2,565
      Helping Hand
      Rank: Community Hero

      Powershell has come a long way and constantly being developed and improved. Those specific cases would be difficult to troubleshoot, but when I had the issues as I develop a lot of modules for API’s, I searched for the error and found the settings in forums. It would be hard to troubleshoot a setting that needs to be set that you can’t see or realize is applicable such as a protocol version that is used by default.

    • #218244
      Senior Moderator
      Topics: 8
      Replies: 1215
      Points: 4,335
      Helping Hand
      Rank: Community Hero

      IMO, All of the above 🙂

      PowerShell’s design helps us to discover almost anything which PowerShell is capable of. For the cmdlets, its the Verb-Noun syntax and joined with the Tab completion feature and Get-Help About_* topics, almost anything in PowerShell can be discovered using PowerShell itself.

      Here for .Net classes, Tab completion is the my first choice, then I mostly switch to docs.microsoft.com. After those two, most of the search ends as I would have got what I need by then.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.