Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Highlighted
mgrenshaw Absent Member.
Absent Member.
3029 views

PowerShell 3 and HPSM Web Services

This took me a while to figure out, finding bits and pieces here and there on internet searches and in HPSM docs.  Here is a script that retrieves a ticket from HPSM via web services and uses a cookie to keep from using multiple sessions/logins.  The authentication piece was a little tricky as well.  It would be easy to modify this script to create/update tickets, etc.  Hopefully this will save you some time and effort.

 

$url = 'http://{servername}:13089/SM/7/IM.wsdl'

$filecookie = "JSESSIONID=" + (Get-Content C:\cookie.txt -ErrorAction SilentlyContinue | Out-String)

$soap = [xml] @"

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7">

<soapenv:Header/>

<soapenv:Body>

<ns:RetrieveIMRequest>

<ns:model>

<ns:keys>

<ns:IncidentID type="String">IM488034</ns:IncidentID>

</ns:keys>

<ns:instance/>

</ns:model>

</ns:RetrieveIMRequest>

</soapenv:Body>

</soapenv:Envelope>

"@

$User = "xxxxx"

$Password = "xxxxx"

$webrequest = Invoke-WebRequest -Uri $url -SessionVariable websession -Method Post -ContentType "text/xml;charset=UTF-8" -Body $soap `

-Headers @{"Set-Cookie" = $filecookie; "SOAPAction" = "Retrieve"; "Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($User+":"+$Password ))}

$cookies = $websession.Cookies.GetCookies($url)

foreach ($cookie in $cookies) {

If ($cookie.name = "JSESSIONID") {$jsessionid = $cookie.value}

}

$jsessionid | Out-File C:\cookie.txt

 

$webrequest.Content

$jsessionid

 

 

 

 

Tags (3)
2 Replies
Absent Member.. madhava_1 Absent Member..
Absent Member..

Re: PowerShell 3 and HPSM Web Services

Hi,

 

Thank you for posting this power shell script. We are also trying to implement webservice call via Powershell. Below is our scrpt. 

 

$url = 'http://winvm373:13081/SM/7/vRealizeapplprofile.wsdl'
$filecookie = "JSESSIONID=" + (Get-Content C:\temp\cookie.txt -ErrorAction SilentlyContinue | Out-String)
$soap = [xml] @"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7">
<soapenv:Header/>
<soapenv:Body>
<ns:RetrievevRealizeapplprofileKeysListRequest>
<ns:model>
<ns:keys>
<ns:ConfigurationItem type="String">SERVICE</ns:ConfigurationItem>
</ns:keys>
<ns:instance>
<ns:file.device type="Structure">
<ns:ConfigurationItem type="String">SERVICE</ns:ConfigurationItem>
</ns:file.device>
<ns:file.applprofile type="Structure">
</ns:file.applprofile>
</ns:instance>
</ns:model>
</ns:RetrievevRealizeapplprofileKeysListRequest>
</soapenv:Body>
</soapenv:Envelope>
"@
$User = "cascwebapi"
$Password = "SMCA3api"
$webrequest = Invoke-WebRequest -Uri $url -SessionVariable websession -Method Post -ContentType "text/xml;charset=UTF-8" -Body $soap -Headers @{"Set-Cookie" = $filecookie; "SOAPAction" = "Retrieve"; "Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($User+":"+$Password ))}
$cookies = $websession.Cookies.GetCookies($url)
foreach ($cookie in $cookies) {
If ($cookie.name = "JSESSIONID") {$jsessionid = $cookie.value}
}
$jsessionid | Out-File C:\temp\cookie.txt
$webrequest.Content
$jsessionid

 

Getting bellow error message,

 

4756( 124) 08/13/2015 10:16:11 JRTE W Send error response: A CXmlApiException was raised in native code : error 16 : scxmlapi(16) - Invalid or missing file name in XML request

 

Please help us to resolve this error. Let meknow if more info required.

 

Thanks & Regards,

Madhava

 

 

Automation
Visitor.

Re: PowerShell 3 and HPSM Web Services

Thank you for this awesoe script..

I could not not locate the proper URL and port no. Is there anyway I can find using my HPSM login access?

Also from the above script I am trying to extarct the description field as .txt file and save to local folder, could you please help us to achive this ???

Your help is highly appriciated!!!

Automation Team

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.