- This topic has 6 replies, 5 voices, and was last updated 1 month, 2 weeks ago by
April 10, 2020 at 8:18 am #217380ParticipantTopics: 6Replies: 18Points: 49Rank: 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.
April 10, 2020 at 8:28 am #217392ParticipantTopics: 4Replies: 2248Points: 5,490Rank: 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
April 10, 2020 at 3:53 pm #217530ParticipantTopics: 12Replies: 1623Points: 2,565Rank: 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.
April 11, 2020 at 2:08 pm #217815ParticipantTopics: 6Replies: 18Points: 49Rank: 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 ?
April 11, 2020 at 3:12 pm #217830ParticipantTopics: 29Replies: 814Points: 2,456Rank: 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.
April 13, 2020 at 2:14 pm #218184ParticipantTopics: 12Replies: 1623Points: 2,565Rank: 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.
April 13, 2020 at 5:49 pm #218244Senior ModeratorTopics: 8Replies: 1215Points: 4,335Rank: 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.
- You must be logged in to reply to this topic.