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

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.

Well … my first thought would be to use my favorite search enginge … :wink:

That would bring up as one of the first hits this:

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.

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 ?

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.

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.

IMO, All of the above :slight_smile:

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 After those two, most of the search ends as I would have got what I need by then.