2

I am pulling data from a web service and want to convert the object data into a string.

I am calling using:

$URI = "http://siteURL"
$Con = New-WebServiceProxy -uri $URI -namespace WebServiceProxy -class Nlyte
$WebCon= $con.GetData('Server')
$OpenCon = [xml] $WebCon

I then query the data:

$OpenCon.Response.Server | Where-Object {$_.AssetID -eq 8186} | Select Asset_x0020_Name

The data comes back as so:

Asset_x0020_Name
----------------
SERVERNAME4001

How can I now take that object data and turn into into a string?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Samuel Meddows
  • 36,162
  • 12
  • 38
  • 36

2 Answers2

3

This may be used:

$OpenCon.Response.Server | Where-Object {$_.AssetID -eq 8186} | Select -ExpandProperty Asset_x0020_Name
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mjolinor
  • 66,130
  • 7
  • 114
  • 135
1

I decided a different approach is the simplest way to go. Instead of trying to convert the individual object values to a string I just put the entire object into a variable and call each value from there.

$Server = $a.Response.Server | Where-Object {$_.AssetID -eq 8186}
$Server.Asset_x0020_Name
Samuel Meddows
  • 36,162
  • 12
  • 38
  • 36