Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Function - XML

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-09-2008   #1 (permalink)
NeilOz
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 SpecsSystem Spec
Old 01-09-2008   #2 (permalink)
Marco Shaw [MVP]
Guest


 

Re: Function - XML

NeilOz wrote:
Quote:

> 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
> }
OK so you:
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 SpecsSystem Spec
Old 01-09-2008   #3 (permalink)
NeilOz
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:
Quote:

> NeilOz wrote:
Quote:

> > 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
> > }
>
> OK so you:
> 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 SpecsSystem Spec
Old 01-09-2008   #4 (permalink)
NeilOz
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:
Quote:

> 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:
>
Quote:

> > NeilOz wrote:
Quote:

> > > 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
> > > }
> >
> > OK so you:
> > 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 SpecsSystem Spec
Old 01-10-2008   #5 (permalink)
Shay Levi
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


Quote:

> 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/L
> iveQuote?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:
>
Quote:

>> 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:
>>
Quote:

>>> NeilOz wrote:
>>>
>>>> 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.asm
>>>> x/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
>>>> }
>>> OK so you:
>>> 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 SpecsSystem Spec
Closed Thread

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


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008