Search code examples
windowspowershellscriptingmalwareexecutionpolicy

powershell web service hello world error log


I can run a "hello world" script, but trying to run this sample script:

C:\Users\thufir\Desktop>
C:\Users\thufir\Desktop>powershell -ExecutionPolicy RemoteSigned
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> type .\stock.ps1
# Working example of how to use PowerShell (version >= 2) to access a web service.
$svc = New-WebServiceProxy –Uri ‘http://www.webservicex.net/stockquote.asmx?WSDL’

$svc | Get-Member  # Use Get-Member to discover the interface of a web service.
# Get stock quotes.
$svc.GetQuote(‘BA’)   # Boeing
$svc.GetQuote(‘AMZN’) # Amazon
$svc.GetQuote(‘SBUX’) # Starbucks
PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> .\stock.ps1


   TypeName: Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1vicex_net_stockquote_a
smx_WSDL.StockQuote

Name                                 MemberType Definition
----                                 ---------- ----------
Disposed                             Event      System.EventHandler Disposed(System.Object, System.EventArgs)
GetQuoteCompleted                    Event      Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes....
Abort                                Method     void Abort()
BeginGetQuote                        Method     System.IAsyncResult BeginGetQuote(string symbol, System.AsyncCallbac...
CancelAsync                          Method     void CancelAsync(System.Object userState)
CreateObjRef                         Method     System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
Discover                             Method     void Discover()
Dispose                              Method     void Dispose(), void IDisposable.Dispose()
EndGetQuote                          Method     string EndGetQuote(System.IAsyncResult asyncResult)
Equals                               Method     bool Equals(System.Object obj)
GetHashCode                          Method     int GetHashCode()
GetLifetimeService                   Method     System.Object GetLifetimeService()
GetQuote                             Method     string GetQuote(string symbol)
GetQuoteAsync                        Method     void GetQuoteAsync(string symbol), void GetQuoteAsync(string symbol,...
GetType                              Method     type GetType()
InitializeLifetimeService            Method     System.Object InitializeLifetimeService()
ToString                             Method     string ToString()
AllowAutoRedirect                    Property   bool AllowAutoRedirect {get;set;}
ClientCertificates                   Property   System.Security.Cryptography.X509Certificates.X509CertificateCollect...
ConnectionGroupName                  Property   string ConnectionGroupName {get;set;}
Container                            Property   System.ComponentModel.IContainer Container {get;}
CookieContainer                      Property   System.Net.CookieContainer CookieContainer {get;set;}
Credentials                          Property   System.Net.ICredentials Credentials {get;set;}
EnableDecompression                  Property   bool EnableDecompression {get;set;}
PreAuthenticate                      Property   bool PreAuthenticate {get;set;}
Proxy                                Property   System.Net.IWebProxy Proxy {get;set;}
RequestEncoding                      Property   System.Text.Encoding RequestEncoding {get;set;}
Site                                 Property   System.ComponentModel.ISite Site {get;set;}
SoapVersion                          Property   System.Web.Services.Protocols.SoapProtocolVersion SoapVersion {get;s...
Timeout                              Property   int Timeout {get;set;}
UnsafeAuthenticatedConnectionSharing Property   bool UnsafeAuthenticatedConnectionSharing {get;set;}
Url                                  Property   string Url {get;set;}
UseDefaultCredentials                Property   bool UseDefaultCredentials {get;set;}
UserAgent                            Property   string UserAgent {get;set;}
exception
exception
exception


PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop>

Is this a policy problem? Or, problem with the script itself?

also:

PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> .\hello.ps1
hi
Cannot convert value "Data Not Found" to type "System.Xml.XmlDocument". Error: "The specified node cannot be inserted
as the valid child of this node, because the specified node is the wrong type."
At C:\Users\thufir\Desktop\hello.ps1:8 char:1
+ [xml]$response = $proxy.GetWeather("Tampa", "United States")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastToXmlDocument

PS C:\Users\thufir\Desktop>
PS C:\Users\thufir\Desktop> type .\hello.ps1



echo "hi"


$proxy = New-WebServiceProxy -Uri http://www.webservicex.net/globalweather.asmx?WSDL
[xml]$response = $proxy.GetWeather("Tampa", "United States")
$response.CurrentWeather | Format-List

PS C:\Users\thufir\Desktop>

Solution

  • It looks to me like an issue with the web service you are calling. It is returning the string "exception". Your code is functioning correctly.

    Navigate to the site Stock Quote Detail and run a test I get an exception returned there as well.