2017-02-25 6 views
0

私はこれを検索しましたが、私はこれを台無しにし続けます。 私はそれは簡単だと思いますが、PowerShellで何もしていないのは助けにはならないと思います:)ループトラフファイルとウェブサービスに送信

私は、ファイル(doc)のディレクトリをループしてWebサービスに送り、pdfファイルdocと同じ名前)。 1つのファイルの

、この作品:

$MyInvocation.MyCommand.Path | Split-Path | Push-Location 

$uri = "http://someinternalurl" 
$doc= "somefilename.doc" 
$pdf= "somefilename.pdf" 

Invoke-WebRequest -Uri $uri -Method POST -InFile $doc-ContentType "application/octet-stream" -OutFile $pdf 

が、私はめちゃくちゃに保つループで、私は現在しようとしている:手を貸すことをいとわ

$files = get-childitem c:\in\doc -Filter *.doc 
ForEach ($file in $files) { 
    $MyInvocation.MyCommand.Path | Split-Path | Push-Location 

    $uri = "http://someinternalurl" 
    $doc = Get-Content $file.Fullname ## <<-- this is where i'm surely wrong 
    $pdf = $file.Basename + '.pdf' 

    Invoke-WebRequest -Uri $uri -Method POST -InFile $in -ContentType "application/octet-stream" -OutFile $pdf 
} 

誰もが?

答えて

0
$DocPath = 'c:\in\doc' 
$Uri = 'http://someinternalurl' 

Get-ChildItem -Path $DocPath -Filter '*.doc' | ForEach-Object { 
    $PdfPath = Join-Path -Path $_.Directory.FullName -ChildPath ($_.BaseName + '.pdf') 
    Invoke-WebRequest -Uri $Uri -Method POST -InFile $_.FullName -ContentType 'application/octet-stream' -OutFile $PdfPath 
} 
+0

ありがとうございます、これはエラーなしで実行され、最終結果は正しい名前のpdfです。残念ながら、それは正しくWebサービスによって処理されていません、その結果は、単語ファイルのプレーンテキストのコンテンツを含むpdfですが、私は今までに得た以上のものです。 – Crimson

関連する問題