Forum Discussion
This script doesn't work if you double-click it. However the command inside the script works perfect
I created a Powershell script with only one command. The command is the one I show below and it works perfectly if you run the command from the Powershell console.
This is the command:
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
However, I created a Powershell script (.ps1) with this only command inside and if I try to run it (double-click on this .ps1 file), I don't receive the expected results...It's like the command doesn't work.
I wonder if I have to add any argument or character along with this command inside the script so the script can work when I double-click on the .ps1 file
Note: Remember that the command works perfectly if you
Please advise, Charles
- LainRobertsonSilver Contributor
Hi, Charles.
What are you expecting to happen?
If you're expecting this command to change the system-wide default for .NET, then this is not how the class works. It only changes the session value, meaning double-clicking the PS1 only changes the value inside that script while it's running.
If that's the only command inside that PS1 then it's effectively achieving nothing since it won't impact any other processes.
You can test this for yourself using your interactive PowerShell console session:
- In your first PowerShell console, run your command to set the session to using Tls12
- Open a new PowerShell console session and simply run:
[System.Net.ServicePointManager]::SecurityProtocol
- Observe that it reflects the system default value, not the value you set in step 1 (assuming your system default isn't specified as Tls12, of course.)
Here's what the example looks like across both consoles:
Cheers,
Lain
- charlesforsCopper Contributor
LainRobertson thank you for your explanation, it clarified several doubts.
Thank you once again, Carlos