我尝试了几种不同的编码方法,从SharePoint网站下载具有已知文件类型( .xlsx)和未知文件类型(。*)的多个文件。但是,到目前为止我所尝试的一切都不起作用。有没有办法做我在这里找到的https://blogs.msdn.microsoft.com/varun_malhotra/2012/02/08/sharepoint-2010-powershell-download-all-files-in-document-library-to-network-share-file-share/,但仅限于文件?
我的工作原理是名称和位置都是静态的文件:
#Setting Path Locations to files to be copied
$SharePoint = "https://Pig.com/MyPig/Breed.docx"
$Path = "$ScriptPath\$MyPig\$Breed\$($MyPig)_$($Breed).docx"
#Get User Information
$UserName = Read-Host "Enter your username as MyUserName@Pig.com"
$Password = Read-Host "Enter your password" -AsSecureString
#Download Files
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile($SharePoint, $Path)
当文件名和类型未知时,上述代码不起作用。你能给我什么建议,我可以开始工作吗?
答案 0 :(得分:0)
如果您可以使用您的凭据,那么这将有效...
# 'http://sharepointsite.com/sites/Site1/ListName/Forms/AllItems.aspx'
# becomes '\\sharepointsite.com\sites\Site1\ListName'
$destPath = 'D:\Temp\SPDocs'
$spPath = '\\sharepointsite.com\sites\Site1\ListName'
Get-ChildItem -Path '\\sharepointsite.com\sites\Site1\ListName' | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $destPath
...否则,试试这个......
$destPath = 'D:\Temp\SPDocs'
$spPath = '\\sharepointsite.com\sites\Site1\ListName'
net use $spPath $password /USER:$username
Get-ChildItem -Path '\\sharepointsite.com\sites\Site1\ListName' | Where-Object { $_.name -like 'MS*' } | Copy-Item -Destination $destPath
net use $spPath /delete
Windows应该从net use
命令