我使用以下文件将文件上传到SharePoint网站:
$sourcefile = "Reportdate.htm"
$sourceFilePath = "D:\$sourcefile"
$siteAddress = "https://Sharepoint.mysite.com/Reports"
$urlDest = "{0}/{1}" -f ($siteAddress, $sourceFile)
$webClient = New-Object System.Net.WebClient
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$webClient.UploadFile($urlDest, "PUT", $sourceFilePath)
我想按日期在新目录中组织上传的文件,我无法找到自动创建新文件夹的方法。
搜索Google等,会显示如何通过FTP进行搜索,但这不可用。如果我可以使用其他方法自动创建文件夹,则不建议安装SharePoint管理单元。
答案 0 :(得分:0)
发现这个网站有答案:
http://jleland.blogspot.com/2010/01/create-directories-and-upload-files-to.html
$url = "https://Sharepoint.mysite.com/Reports/Reports/$date"
$req = [System.Net.HttpWebRequest]::Create($url)
$req.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$req.Method = "MKCOL"
$res = $req.GetResponse()
所以我的最终脚本检查新目录是否存在,如果不存在则
$url = "https://Sharepoint.mysite.com/Reports/Reports/$date"
$check = ((wget $url -UseDefaultCredentials -ea 0).statuscode)
If ($check -ne "200") {
$req = [System.Net.HttpWebRequest]::Create($url)
$req.Credentials = [System.Net.CredentialCache]::DefaultCredentials
$req.Method = "MKCOL"
$req.GetResponse()
}
答案 1 :(得分:0)
要将MkCol与更简单的Invoke-WebRequest
一起使用:
Invoke-WebRequest `
-Uri $url `
-Credential $cred `
-CustomMethod 'MkCol'
# -SkipCertificateCheck # at your own risk, only on PS>6