Powershell脚本将日志文件从本地系统上传到http URL

时间:2014-08-18 04:09:13

标签: powershell-v2.0 powershell-v3.0

我如何使用powershell脚本将日志文件从本地系统上传到网页(http://abc.。)? 提前致谢

1 个答案:

答案 0 :(得分:3)

如果您使用的是HTTP,请尝试以下方法:

    $sourceFilePath = "c:\MyLocalFolder\LocalLogFileName.log"
    $siteAddress = "http://192.168.15.12/DestinationFolder"
    $urlDest = "{0}/{1}" -f ($siteAddress, "DestinationLogFileName.log";
    $webClient = New-Object System.Net.WebClient;
    $webClient.Credentials = New-Object System.Net.NetworkCredential("MyUserName", "MyPassword");
    ("*** Uploading {0} file to {1} ***" -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green -BackgroundColor Yellow
    $webClient.UploadFile($urlDest, "PUT", $sourceFilePath);