I'm trying to create a Rest API's from a power shell, when i'm trying to run the script i'm getting the following error. I wasn't sure what i was making a mistake.
I'll put the script and the error also. Please help.
Script:
username = "admin"
password = "******"
authInfo = ("{0}:{1}" -f $username,$password)
authInfo = [System.text.Encoding]:: UTF8.GetByteCount($authInfo)
authInfo = [System.Convert]::ToBase64String($authInfo)
headers = @{Accept=("application/json");Contenttype=("appliaction/json");Authorization=("Basic {0}"-f $authInfo)}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::"tls12, tls11, tls"
Invoke-WebRequest -Uri https://njidlsdsapp01/support
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
uri = "https://njidlsdsapp01/support"
body = "{'login':'admin','login_pwd':'*****','commands' :['create a new support file']}"
headers
res = invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body
res
Error: PS C:\Users\njujjavarapu> C:\Users\njujjavarapu\Desktop\Snapshot.ps1 Exception setting "SecurityProtocol": "Cannot convert null to type "System.Net.SecurityProtocolType" due to enumeration values that are not valid. Specify one of the following enumeration values and try again. The possible enumeration values are "SystemDefault,Ssl3,Tls,Tls11,Tls12"." At C:\Users\njujjavarapu\Desktop\Snapshot.ps1:7 char:1 + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolTy ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException + FullyQualifiedErrorId : ExceptionWhenSetting
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel. At C:\Users\njujjavarapu\Desktop\Snapshot.ps1:8 char:1 + Invoke-WebRequest -Uri https://njidlsdsapp01/support + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Name Value
---- -----
Contenttype appliaction/json
Accept application/json
Authorization Basic Eg==
invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel. At C:\Users\njujjavarapu\Desktop\Snapshot.ps1:19 char:8 + $res = invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Bo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand