I'm trying to run a Powershell command to download and run a exe. To be compatible with win 8.1 i'vs researched that i have to use ssl 1.2 (Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel) Although running this command:
[Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
brings the error: The term ::SecurityProtocol
is not recognized as the name of cmdlet, function, script file, or operable program. Checkthe spelling of the name, or if a path was included, verify that the path is correct and try again.
The whole command i'm running look like this:
powershell.exe [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ;
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ;
& $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install
Anybody know why this error occurs? Or is there even an easier way to run this? I've done much research and couldn't find anything helpful.
EDIT 1: After running the command in powershell directly (without the powershell.exe at the beginning) it worked fine (also replaced "&"; with "&") although running it through the msi installer it doesn't. My Custom Action in Product.wxs:
<CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='powershell.exe [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ;
& $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install' Return='check'/>
EDIT 2
It seems to be that by building the Project it misses the statements in the square brackets atleast that causes the particular error message. Does Anybody know another way to write that statement or do i have to put something before/after the brackets?
CodePudding user response:
I found the solution, you have to put the execommand
in its own property, then you have to execute the property. This way the []
are not getting deleted:
<Property Id='EXECOMMAND' Value='powershell.exe -windowstyle hidden [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ; Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; & $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install'/>
<CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='[EXECOMMAND]' Return='check'/>