Hi,
I'm quite new to powershell and proxmox im trying to use the restful API service on proxmox to manage nodes from powershell.
at the moment im struggling to get started as when i try to get a ticket, is not taking it, im using part of the code in this post https://forum.proxmox.com/threads/p...to-respond-properly-through-powershell.22507/
which got me a SSL/TLS error and need this done :
afther setting this up to ignore ssl error running my code would return me this error:
I have noticed also that when accesing the url from a browser I get that same result, dont know if it related or I'm doing something wrong.
Any help would be appreciated.
Thanks.
\Marco
I'm quite new to powershell and proxmox im trying to use the restful API service on proxmox to manage nodes from powershell.
at the moment im struggling to get started as when i try to get a ticket, is not taking it, im using part of the code in this post https://forum.proxmox.com/threads/p...to-respond-properly-through-powershell.22507/
Code:
function Create-Cookie($name, $value, $domain, $path){
$c=New-Object System.Net.Cookie;
$c.Name=$name;
$c.Path=$path;
$c.Value = $value;
$c.Domain =$domain;
$c.Expires = ($c.TimeStamp).AddMinutes("20");
return $c;
}
# Add your variables here......
$uri="https://IP:8006/api2/json"
$domain=".<yourdomain>"
$ticketuri = $uri+'/access/ticket'
$apipath='/api2/json'
$body =@{
username='user'@<PAM|PVE>'
password='pass'
}
# First request: Get a ticket
write-host "Requesting ticket from Proxmox:"
$ticket = Invoke-RestMethod -Method Post -Uri $ticketuri -Body $body -SessionVariable $proxmox -verbose
which got me a SSL/TLS error and need this done :
Code:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
afther setting this up to ignore ssl error running my code would return me this error:
VERBOSE: POST https://10.20.30.228:8006/api2/json/access/ticket with -1-byte payload
Invoke-RestMethod : {"data":null}
At line:25 char:11
+ $ticket = Invoke-RestMethod -Method Post -Uri $ticketuri -Body $body ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
I have noticed also that when accesing the url from a browser I get that same result, dont know if it related or I'm doing something wrong.
Any help would be appreciated.
Thanks.
\Marco