Highlighted
Absent Member.
Absent Member.
2027 views

Can't connect Rest API per PowerShell

Hallo

I'am try to connect the Rest API and read out the Domains.
In the browser this works after get in my credentials.
In PowerShell this works not, error message "... the underlying connection was closed..."

Where can i find examples for rest api calls per powershell?

Best regards
HP
Labels (1)
0 Likes
6 Replies
Highlighted
Knowledge Partner
Knowledge Partner

It may help if you provide the actual powershell lines you are using,
though personally it sounds like the issue is on the powershell side since
the browser works properly. You may want to look at the traffic on the
wire to see how the requests differ, as that would seem to give the
quickest path to a solution other than checking GW admin service logs.


--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the
forum as I do not use the web interface often.
0 Likes
Highlighted
Absent Member.
Absent Member.

Just happened to have a PS script to read all the Domains:


$server = read-host "GroupWise Admin Server IP/Hostname: "
$port = read-host "GroupWise Admin Service Port: "

$admin = read-host "GroupWise Administrator: "
$pwd = Read-Host "Password for GW administrator: "

$encodedPwd = convertto-securestring $pwd -AsPlainText -Force

#Needed to ignore self signed cert from GW admin service
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
# Ignore homemade certs end
# Create GWadmin Credentials in the correct format and add to headers variable
$encoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($admin + ":" + $pwd))
$Global:headers = @{Authorization = "Basic "+ $encoded}

$gwtesturl = "https://" + $server + ":" + $port + "/gwadmin-service/domains"
$results = Invoke-RestMethod -Uri $gwtesturl -Headers $headers -Method GET
write-host $results.object


--Morris


haraldpfirmann;2476193 wrote:
Hallo

I'am try to connect the Rest API and read out the Domains.
In the browser this works after get in my credentials.
In PowerShell this works not, error message "... the underlying connection was closed..."

Where can i find examples for rest api calls per powershell?

Best regards
HP
0 Likes
Highlighted
Absent Member.
Absent Member.

Here's a little extra, it will iterate through the domain list and just print out the domain name..

foreach ($obj in $results.object) {
write-host $obj.name
}

--MB
0 Likes
Highlighted
Absent Member.
Absent Member.

In the browser must i in Dialog insert my credentials.
The GW Server is in a other Domain.
I'm get in my credentials: test@gwdomain-one.com and Password
How get i in powershell my username with Domain?
Domain\username or username@domain? Both works not!
Is cross Domains in PS possible?

Thanks for your answers

mblackham;2476212 wrote:
Just happened to have a PS script to read all the Domains:


$server = read-host "GroupWise Admin Server IP/Hostname: "
$port = read-host "GroupWise Admin Service Port: "

$admin = read-host "GroupWise Administrator: "
$pwd = Read-Host "Password for GW administrator: "

$encodedPwd = convertto-securestring $pwd -AsPlainText -Force

#Needed to ignore self signed cert from GW admin service
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
# Ignore homemade certs end
# Create GWadmin Credentials in the correct format and add to headers variable
$encoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($admin + ":" + $pwd))
$Global:headers = @{Authorization = "Basic "+ $encoded}

$gwtesturl = "https://" + $server + ":" + $port + "/gwadmin-service/domains"
$results = Invoke-RestMethod -Uri $gwtesturl -Headers $headers -Method GET
write-host $results.object


--Morris
0 Likes
Highlighted
Absent Member.
Absent Member.

Sorry, I'm not a AD/Powershell expert. Have no idea what you would need to do or why you want to.

--Morris


haraldpfirmann;2476278 wrote:
In the browser must i in Dialog insert my credentials.
The GW Server is in a other Domain.
I'm get in my credentials: test@gwdomain-one.com and Password
How get i in powershell my username with Domain?
Domain\username or username@domain? Both works not!
Is cross Domains in PS possible?

Thanks for your answers
0 Likes
Highlighted
Absent Member.
Absent Member.

MB

Thanks for this. I played around with your example and ended up finding an old account that was taking up 20+ Gig of space.

Richard
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.