Powershell script to Upload log file from local sy

2020-07-18 03:59发布

How could i upload a log file from my local system to a webpage (http://abc..) using powershell script? Thanks in advance

1条回答
我欲成王,谁敢阻挡
2楼-- · 2020-07-18 04:59

If you are using HTTP, try something like this:

    $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);
查看更多
登录 后发表回答