PowerShell : Upload file to WebDav Server
A new PowerShell for upload one file to a WebDav Server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ######################################## #Webdav Access with PowerShell ######################################## #Put the complete path of your file $file = "D:\test.txt" #Put the url without the last "/" $url = "http://mywebSite/webdav" #Provide User and Pwd for Webdav Access $user = "user" $pass = "pwd" ######################################## #Script ####################################### #Adding the name of the file at the end of the URL $url += "/" + $file.split('\')[(($file.split("\")).count - 1)] #Connecting to WebDav Write-Host "File upload started" # Set binary file type Set-Variable -name adFileTypeBinary -value 1 -option Constant $objADOStream = New-Object -ComObject ADODB.Stream $objADOStream.Open() $objADOStream.Type = $adFileTypeBinary $objADOStream.LoadFromFile("$file") $arrbuffer = $objADOStream.Read() $objXMLHTTP = New-Object -ComObject MSXML2.ServerXMLHTTP $objXMLHTTP.Open("PUT", $url, $False, $user, $pass) $objXMLHTTP.send($arrbuffer) Write-Host "File upload finished" |

