2017-09-25 86 views
0

我試圖將一個變量(日期)轉換爲XML文章,但是我無法使其工作。 在XML文章中,我需要指定2個日期(vndg = today和morg = today + 1)。使用PowerShell解析XML POST請求中的變量

這是我的PowerShell腳本,它的工作原理沒有日期變量。

$vndg = (Get-Date).ToString("dd-MM-yyyy") 
$morg = (Get-Date).AddDays(+1).ToString("dd-MM-yyyy") 

[XML]$SOAP = @' 
<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <Clocking_GetByDateRangeUtc xmlns="http://www.geodynamics.be/webservices"> 
     <caller> 
     <CompanyName>companyname</CompanyName> 
     <LoginName>username</LoginName> 
     <Password>password</Password> 
     </caller> 
     <fromDateUtc>$vndg</fromDateUtc> 
     <toDateUtc>$morg</toDateUtc> 
    </Clocking_GetByDateRangeUtc> 
    </soap:Body> 
</soap:Envelope> 
'@ 

$headers = @{"SOAPAction" = "http://www.geodynamics.be/webservices/Clocking_GetByDateRangeUtc"} 
$destination = 'C:\Temp\GeoDynamics\Downloads\GeoPers.xml' 

$URI = "https://secure.geodynamics.be/webservices/intellitracer/1.0/IntegratorWebservice.asmx?WSDL" 
$out = Invoke-WebRequest $uri -Method Post -ContentType 'text/xml' -Body $SOAP -Headers $headers -OutFile $destination 
+0

'@ '...' @' - >'@ 「......」 @' –

+0

如果我這樣做那麼我得到一個錯誤==>字符串'25 -09-2017'不是有效的AllXsd值。 –

+0

我通過改變日期變量的格式來工作==> $ vndg =(get-date).ToString(「yyyy-MM-ddT00:00:00」) $ morg =(get-date)。 AddDays(+1).ToString(「yyyy-MM-ddT00:00:00」) –

回答

0

我把它通過改變腳本以下工作:

[XML]$SOAP = @" 
<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <Clocking_GetByDateRangeUtc xmlns="http://www.geodynamics.be/webservices"> 
     <caller> 
     <CompanyName>name</CompanyName> 
     <LoginName>login</LoginName> 
     <Password>password</Password> 
     </caller> 
     <fromDateUtc>$vndg</fromDateUtc> 
     <toDateUtc>$morg</toDateUtc> 
    </Clocking_GetByDateRangeUtc> 
    </soap:Body> 
</soap:Envelope> 
"@