简体   繁体   中英

Convert PowerShell object to string

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?

可以使用:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM