Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

You cannot call a method on a null-valued expression.

$
0
0

Hi,

I am trying to run a HP Warranty Lookup script that I stumbled upon and I am getting a couple of "You cannot call a method on a null-valued expression." errors...

I am still learning Powershell and I am stumped as to what is wrong...

Here is the code - it is saved as 'HPWarrantyCheck-Upload.ps1' and executed as '.\HPWarrantyCheck-Upload.ps1 CZ23100B7R 642119-421'

Param(

    [string]$serial,

    [string]$product,

    [string]$country = 'GB'

)

 

#$product = Get-WmiObject -Namespace root\wmi -class ms_systeminformation | Select -ExpandProperty SystemSKU

#$serial = Get-WmiObject win32_bios | Select-Object -ExpandProperty SerialNumber

 

$reqRegNs = @{

    'SOAP-ENV' = 'http://schemas.xmlsoap.org/soap/envelope/'

    'iseeReg'  = 'http://www.hp.com/isee/webservices/'

    'isee'     = 'http://www.hp.com/schemas/isee/5.00/event'

}

 

$reqWarNs = @{

    'SOAP-ENV' = 'http://schemas.xmlsoap.org/soap/envelope/'

    'iseeReg'  = 'http://www.hp.com/isee/webservices/'

    'isee'     = 'http://www.hp.com/isee/webservices/'

}

 

$reqWarEntNs = @{

    'SOAP-ENV' = 'http://schemas.xmlsoap.org/soap/envelope/'

    'isee'     = 'http://www.hp.com/schemas/isee/5.00/entitlement'

}

 

$resNs = @{

    'soap'     = 'http://schemas.xmlsoap.org/soap/envelope/'

    'isee'     = 'http://www.hp.com/isee/webservices/'

}

 

function IseeRequest([string]$service, [string]$action, [xml]$body)

{

    $res = Invoke-WebRequest `

        -UseBasicParsing `

        -Method Post `

        -ContentType 'text/xml; charset=utf-8' `

        -Uri "https://services.isee.hp.com/$($service)/$($service)Service.asmx" `

        -Headers @{'SOAPAction' = "http://www.hp.com/isee/webservices/$($action)"} `

        -UserAgent 'RemoteSupport/A.05.05 - gSOAP/2.7' `

        -Body $body.OuterXml

 

    [xml]$doc = $res.Content

 

    $isSuccess = ($doc | Select-Xml -Namespace $resNs "//soap:Envelope/soap:Body/isee:$($action)Response/isee:$($action)Result/isee:IsSuccess").Node.InnerText -as [bool]

 

    if (!$isSuccess) {

        $doc.OuterXml

        $err = ($doc | Select-Xml -Namespace $resNs "//soap:Envelope/soap:Body/isee:$($action)Response/isee:$($action)Result/isee:Error").Node.InnerText

        Write-Error "ISEE request failed: $($err)"

        Exit

    }

 

    return $doc

}

 

#

# Register session

#

 

$curTime = Get-Date -Date (Get-Date).ToUniversalTime() -UFormat '%Y/%m/%d %H:%M:%S GMT'

 

 

[xml]$regEnv = '<SOAP-ENV:Envelope

    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

    xmlns:iseeReg="http://www.hp.com/isee/webservices/">

  <SOAP-ENV:Body>

    <iseeReg:RegisterClient2>

      <iseeReg:request/>

    </iseeReg:RegisterClient2>

  </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

'

 

[xml]$regReq = '<isee:ISEE-Registration schemaVersion="5.00"

    xmlns:isee="http://www.hp.com/schemas/isee/5.00/event">

  <RegistrationSource>

    <HP_OOSIdentifiers>

      <OSID>

        <Section name="SYSTEM_IDENTIFIERS">

          <Property name="TimestampGenerated"/>

        </Section>

      </OSID>

      <CSID>

        <Section name="SYSTEM_IDENTIFIERS">

          <Property name="CollectorType" value="MC3"/>

          <Property name="CollectorVersion" value="T05.80.1 build 1"/>

          <Property name="AutoDetectedSystemSerialNumber" value="10"/>

          <Property name="SystemModel" value="HP ProLiant"/>

          <Property name="TimestampGenerated"/>

        </Section>

      </CSID>

    </HP_OOSIdentifiers>

    <PRS_Address>

      <AddressType>0</AddressType>

      <Address1/>

      <Address2/>

      <Address3/>

      <Address4/>

      <City/>

      <Region/>

      <PostalCode/>

      <TimeZone/>

      <Country/>

    </PRS_Address>

  </RegistrationSource>

  <HP_ISEECustomer>

    <Business/>

    <Name/>

  </HP_ISEECustomer>

  <HP_ISEEPerson>

    <CommunicationMode>255</CommunicationMode>

    <ContactType/>

    <FirstName/>

    <LastName/>

    <Salutation/>

    <Title/>

    <EmailAddress/>

    <TelephoneNumber/>

    <PreferredLanguage/>

    <Availability/>

  </HP_ISEEPerson>

</isee:ISEE-Registration>

'

 

 

($regReq | Select-Xml -Namespace $reqRegNs '//isee:ISEE-Registration/RegistrationSource/HP_OOSIdentifiers/OSID/Section/Property[@name="TimestampGenerated"]').Node.SetAttribute('value', $curTime)

($regReq | Select-Xml -Namespace $reqRegNs '//isee:ISEE-Registration/RegistrationSource/HP_OOSIdentifiers/CSID/Section/Property[@name="TimestampGenerated"]').Node.SetAttribute('value', $curTime)

 

 

($regEnv | Select-Xml -Namespace $reqRegNs '//SOAP-ENV:Envelope/SOAP-ENV:Body/iseeReg:RegisterClient2/iseeReg:request').Node.InnerXml = $regEnv.CreateCDataSection($regReq.OuterXml).OuterXml

 

Write-Output 'Registrating session...'

[xml]$regRes = IseeRequest 'ClientRegistration' 'RegisterClient2' $regEnv

 

$gdid  = ($regRes | Select-Xml -Namespace $resNs '//soap:Envelope/soap:Body/isee:RegisterClient2Response/isee:RegisterClient2Result/isee:Gdid').Node.InnerText

$token = ($regRes | Select-Xml -Namespace $resNs '//soap:Envelope/soap:Body/isee:RegisterClient2Response/isee:RegisterClient2Result/isee:RegistrationToken').Node.InnerText

 

Write-Output "Got session id $($gdid)"

 

#

# Warranty lookup

#

 

[xml]$warEnv = '<SOAP-ENV:Envelope

    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

    xmlns:isee="http://www.hp.com/isee/webservices/">

  <SOAP-ENV:Header>

    <isee:IseeWebServicesHeader>

      <isee:GDID/>

      <isee:registrationToken/>

      <isee:OSID/>

      <isee:CSID/>

    </isee:IseeWebServicesHeader>

  </SOAP-ENV:Header>

  <SOAP-ENV:Body>

    <isee:GetOOSEntitlementList2>

      <isee:request/>

    </isee:GetOOSEntitlementList2>

  </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

'

 

[xml]$warReq = '<isee:ISEE-GetOOSEntitlementInfoRequest

    xmlns:isee="http://www.hp.com/schemas/isee/5.00/entitlement"

    schemaVersion="5.00">

  <HP_ISEEEntitlementParameters>

    <CountryCode/>

    <SerialNumber/>

    <ProductNumber/>

    <EntitlementType/>

    <EntitlementId/>

    <ObligationId/>

  </HP_ISEEEntitlementParameters>

</isee:ISEE-GetOOSEntitlementInfoRequest>

'

 

($warReq | Select-Xml -Namespace $reqWarEntNs '//isee:ISEE-GetOOSEntitlementInfoRequest/HP_ISEEEntitlementParameters/CountryCode').Node.InnerText = $country

($warReq | Select-Xml -Namespace $reqWarEntNs '//isee:ISEE-GetOOSEntitlementInfoRequest/HP_ISEEEntitlementParameters/SerialNumber').Node.InnerText = $serial

($warReq | Select-Xml -Namespace $reqWarEntNs '//isee:ISEE-GetOOSEntitlementInfoRequest/HP_ISEEEntitlementParameters/ProductNumber').Node.InnerText = $product

 

($warEnv | Select-Xml -Namespace $reqWarNs '//SOAP-ENV:Envelope/SOAP-ENV:Header/isee:IseeWebServicesHeader/isee:GDID').Node.InnerText = $gdid

($warEnv | Select-Xml -Namespace $reqWarNs '//SOAP-ENV:Envelope/SOAP-ENV:Header/isee:IseeWebServicesHeader/isee:registrationToken').Node.InnerText = $token

($warEnv | Select-Xml -Namespace $reqWarNs '//SOAP-ENV:Envelope/SOAP-ENV:Body/isee:GetOOSEntitlementList2/isee:request').Node.InnerXml = $warEnv.CreateCDataSection($warReq.OuterXml).OuterXml

 

Write-Output 'Requesting warranty...'

[xml]$warRes = IseeRequest 'EntitlementCheck' 'GetOOSEntitlementList2' $warEnv

 

Write-Output 'Dumping warranty payload:'

$warxml =  ($warRes | Select-Xml -Namespace $resNs '//soap:Envelope/soap:Body/isee:GetOOSEntitlementList2Response/isee:GetOOSEntitlementList2Result/isee:Response').Node.InnerText

 

$warxml =  (($warxml.Substring($warxml.IndexOf('<EndDate>'),19)))

 

$warxml =  $Warxml.Trim('<EndDate>')

 

$props = @{

            'Warranty Expires:' = $warxml;

            'Serial No:'        = $Serial;

            'Product Code'      = $Product;

            'Country Code'      = $Country

          }

 

New-Object -TypeName psobject -Property $props

 

The errors are on lines 192 and 194 as follows:

 

 

PS C:\Users\Martin\Documets\SkyDrive\Documents\PowerShell Stuff\HP Warranty Lookup> .\HPWarrantyCheck-Upload.ps1 CZ23100B7R 642119-421

Registrating session...

Got session id 

Requesting warranty...

Dumping warranty payload:

You cannot call a method on a null-valued expression.

At C:\Users\Martin\Documents\SkyDrive\Documents\PowerShell Stuff\HP Warranty Lookup\HPWarrantyCheck-Upload.ps1:192 char:1

+ $warxml =  (($warxml.Substring($warxml.IndexOf('<EndDate>'),19)))

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

 

You cannot call a method on a null-valued expression.

At C:\Users\Martin\Documents\SkyDrive\Documents\PowerShell Stuff\HP Warranty Lookup\HPWarrantyCheck-Upload.ps1:194 char:1

+ $warxml =  $Warxml.Trim('<EndDate>')

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

 

 

Country Code                      Product Code                      Serial No:                       Warranty Expires:               

------------                      ------------                      ----------                       -----------------               

GB                                642119-421                        CZ23100B7R                                                       

 

 

 

PS C:\Users\Martin\Documents\SkyDrive\Documents\PowerShell Stuff\HP Warranty Lookup> 

 

 

The expiry date I am expecting to be returned for this server is 6th April 2016 - currently it is empty...

 

Am help you can offer will be greatly appreciated...

 

Thanks

Martin

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles