![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Function - XML I've created this function to recieve an XML Document from one of our Web servers. The $Quote.Quote.BestBuyPrice returns the value of System.XML.XMLDocument.Quote.BestBuyPrice. When I run it as a normal script it gets the correct data, is there different syntax etc for functions? function Get-Quote { param([String]$Code) $WebClient = New-Object System.Net.WebClient [xml]$Quote = $Webclient.DownloadString("http://server:1891/MarketInfoService.asmx/LiveQuote?Code="+$Code) Start-Sleep -Seconds 2 #While it recieves the results. Write-Host "The current best buy price for $Code is $Quote.Quote.BestBuyPrice at $Quote.Quote.QuoteTime } |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Function - XML NeilOz wrote:
1. Put this entire function in a ps1 script, then simply call get-quote on the script. 2. Enter this function from the command line directly into your current shell, then call get-quote directly. You're saying that #1 doesn't work the same as #2? How about putting the function into a ps1 script, dot-sourcing that ps1, and then trying the function? Really all 3 of these should work exactly the same, all things being equal. Do you get any output/errors? -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Function - XML if i go $Code = "xxx" $WebClient = New-Object System.Net.WebClient [xml]$Quote = $Webclient.DownloadString("http://server:1891/MarketInfoService.asmx/LiveQuote?Code="+$Code) $Time = $Quote.Quote.QuoteTime $BestBuy = $Quote.Quote.BestBuyPrice $time and $bestbuy both come up with the correct figures. But from within the function they return "System.Xml.XmlDOcument.Quote.BestBuyPrice" After . sourcing the .ps1 and running $Code is returns the correct value, so the issue I believe is with the line [xml]$Quote = $Webclient.DownloadString("http://server:1891/MarketInfoService.asmx/LiveQuote?Code="+$Code). "Marco Shaw [MVP]" wrote:
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Function - XML My own silly mistake. Here is the correct code.. function Get-Quote { param([String]$Code) $WebClient = New-Object System.Net.WebClient [xml]$Quote = $Webclient.DownloadString("http://server:1891/MarketInfoService.asmx/LiveQuote?Code=$Code") Start-Sleep -Seconds 2 #While it recieves the results. Write-Host "The current best buy price for $Code is" return $Quote.Quote.BestBuyPrice "at" $Quote.Quote.QuoteTime } "NeilOz" wrote:
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #5 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Function - XML NeilOz, You can remove the sleep statement, it doesn't count. Can you post a sample XML result? ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I tell if a function is already defined? | Kevin Buchan | PowerShell | 3 | 02-06-2008 07:50 AM |
| Send To function | Bill Garcia | Vista General | 7 | 01-25-2008 10:24 AM |
| 'Send To' function | Alfred Lorona | Vista General | 2 | 06-12-2007 12:54 AM |
| possible function bug? | klumsy@xtra.co.nz | PowerShell | 1 | 09-29-2006 06:02 PM |
| BUG: Redirecting function contents to a file truncates function lines at the width of the console | Adam Milazzo | PowerShell | 2 | 08-11-2006 10:58 PM |