[ngw] GW2014 REST-API and PowerShell

James Taylor James.Taylor at eastcobbgroup.com
Wed Feb 25 23:07:07 UTC 2015


And so you did...and I was even there.
What once was lost, now is found.
Thanks,
-jt 
 
>>> "Morris Blackham" <mblackham at gw.novell.com> 2/25/2015 3:55 PM >>> 
James and all,  Dan Christensen did a Brainshare session on using curl
for admin functions.   If you have access to the brainshare materials,

his presentation should be available there.   If you don't have access,

let me know and I'll send it to you. But for now:

Here's a script to change a user password..   I've added some comments
to hopefully clarify what's going on.

#/bin/bash
# ---  ipaddr, port and administrator for gwadmin service
IP=10.10.10.10
PORT=9710
GWADMIN=admin

# ----  Prompt for admin pwd so it isn't revealed in the script
echo "Enter GroupWise Admin Password: "
read ADMINPWD

# --- Prompt for GW userid, his/her postoffice and new pwd
# ---  We want the postoffice in case there are duplicate userids in
the sytem 
echo "Enter GroupWise UserID for password change: "
read GWID
echo "Enter Post Office for $GWID: "
read PO
echo "Enter new password for $GWID: "
read NEWPWD

#--  build base url for admin service
BASEURL="https://$IP:$PORT/gwadmin-service"

# --- create json data for the new password
DATA="{\"userPassword\":{\"value\":\"$NEWPWD\"}}"

# --- build url to search for the user.  the /list/user.csv  will
return the user data in csv format.
# --- attrs= returns only the users domain,po and gwid, so we can
build
the url to change the pwd
SEARCHURL="$BASEURL/list/user.csv?name=$GWID&postoffice=$PO&attrs=domain,postoffice,name"

# --- use curl to search the admin service for the user,and gawk to
build the proper user url
url=`curl -k --user $GWADMIN:$ADMINPWD $SEARCHURL |gawk
--field-separator=, 'NR!=1 {print
"'$BASEURL'/domains/"$1"/postoffices/"$2"/users/"$3"/clientoptions"}'`

# --- now use curl to change the pwd.  note content-type cause were
using a json doc
curl -k --user $GWADMIN:$ADMINPWD -H "Content-Type:application/json"
-X
PUT $url --data $DATA
echo "Password changed"
# --- end of script


Speaking of a csv file,  here's one to export all user data to a csv
file

curl -k --user admin:novell
https://10.10.10.10:9710/gwadmin-service/list/user.csv > myusers.csv


And a one liner command to clear the Login Disable setting for a user.

just change the pertinent data.

curl --k --user admin:pwd -H "Content-type:application/json" -X PUT
--data "{\"loginDisabled\":\"false\"}"
https://10.10.10.10:9710/gwadmin-service/domains/mydom/postoffice/mypo/users/myuser

>>> "James Taylor" <James.Taylor at eastcobbgroup.com> 2/25/2015 10:55 AM
>>>
Hi Morris -
The web based doc for access to the GW2014 functions are great, but I
haven't been able to find any good examples of usage for bash scripts
or
command strings I can use on linux.
Are they out there anywhere?
-jt 


James Taylor
678-697-9420
james.taylor at eastcobbgroup.com



>>> "Morris Blackham" <mblackham at gw.novell.com> 2/25/2015 11:19 AM >>>

Uwe,  took your example,  tweaked variables to match my system,  and
it
worked for me with  PwrShell v4 on Win2012R2.  Not sure what is the
issue with yours.

FYI,  you can modify the command to search for a FID, 
gwadmin-service/list/user?fileId=xxx
That way,  you don't have to know the domain or po for the user.   Or
maybe you knew that already...

--Morris
>>> "Barth Uwe" <Uwe.Barth at stadt-chemnitz.de> 2/25/2015 2:01 AM >>>
Hello,

actually I try to use PowerShell v4 for some GroupWise administration
tasks via REST-API. Unfortunately I'm unable to send a simple
Invoke-RestMethod command like this:

<code>
$uri = "https://grpwise.example.com:9710/gwadmin-service"
$gwuser = "johndoe"
$gwpwd = "johndoespassword"
$gwdom = "gwdom"
$gwpo = "gwpo"
$gwfid = "3qq"
$uri += "/domains/" + $gwdom +"/postoffices/" + $gwpo +
"/users?fileId=" + $gwfid
$encoded =
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($gwuser+":"+$gwpwd
))
$headers = @{Authorization = "Basic "+$encoded}
Invoke-RestMethod -Uri $uri -Headers $headers -Method GET -Verbose 
</code>

I always get an error like this:

<error>C:\> C:\gwhelper\gwrest.ps1
https://grpwise.example.com:9710/gwadmin-service/domains/gwdom/postoffices/gwpo/users?fileId=3qq

AUSFÜHRLICH: GET
https://grpwise.example.com:9710/gwadmin-service/domains/gwdom/postoffices/gwpo/users?fileId=3qq
with 0-byte payload
Invoke-RestMethod : The underlying connection was closed: An
unexpected
error occurred on a send.
In  C:\gwhelper\gwrest.ps1:23 Zeichen:1
+ Invoke-RestMethod -Uri $uri -Headers $headers -Method GET -Verbose
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo  	    : InvalidOperation:
(System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod],
WebException
    + FullyQualifiedErrorId :
WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
</error>

The resulting uri is correct (tested with browser). CA-Certificate is
imported in Windows CertStore. Before the import I got a clear SSL
certificate error message for this.

Does someone here use PowerShell v4 with Invoke-RestMethod
successfully?

Uwe

_______________________________________________
ngw mailing list
ngw at ngwlist.com
http://ngwlist.com/mailman/listinfo/ngw

_______________________________________________
ngw mailing list
ngw at ngwlist.com
http://ngwlist.com/mailman/listinfo/ngw



More information about the ngw mailing list