我有一个脚本,可以将所有文件从文件夹上传到SharePoint网站:
asnp "*sh*"
$url=Read-Host "Enter Site Url"
$web=Get-SPWeb -Identity $url
if($web)
{
try
{
$list = $web.Lists.TryGetList("Documents")
$files = Get-ChildItem -Path "D:\Manju" -Force -Recurse
foreach ($file in $files)
{
$stream = $file.OpenRead()
$done= $list.RootFolder.Files.Add($file.Name, $stream, $true)
Write-Host $done.Name "Uploaded into the Site" -BackgroundColor Green
}
}
catch
{
$ErrorMessage = $_.Exception.Message
Write-Host $ErrorMessage -BackgroundColor Yellow
}
}
asnp "*sh*"
$url=Read-Host "Enter Site Url"
$web=Get-SPWeb -Identity $url
if($web)
{
try
{
$list = $web.Lists.TryGetList("Documents")
$files = Get-ChildItem -Path "D:\Manju" -Force -Recurse
foreach ($file in $files)
{
$stream = $file.OpenRead()
$done= $list.RootFolder.Files.Add($file.Name, $stream, $true)
Write-Host $done.Name "Uploaded into the Site" -BackgroundColor Green
}
}
catch
{
$ErrorMessage = $_.Exception.Message
Write-Host $ErrorMessage -BackgroundColor Yellow
}
}
else
{
Write-Host "Site Doesn't exist"
}
$list.Update();else
{
Write-Host "Site Doesn't exist"
}
$list.Update();
如果我运行它并将url放在提示符(http://teams-test.xxxxx.com/sites/projects/Business/prints/Houseprints/Forms/AllItems.aspx)内,它总是说
写主机"网站不存在"
答案 0 :(得分:0)
确保在具有足够权限的用户帐户下运行脚本。它必须能够直接访问站点所在的内容数据库,当然还有配置数据库。
答案 1 :(得分:0)
由于Get-SPWeb cmdlet期望提供有效的网站网址,因此会发生此错误。
在您的案例中,而不是指定为Get-SPWeb参数的列表视图网址,请尝试指定网址:http://teams-test.xxxxx.com/sites/projects/Business/prints/
更新
该帐户似乎没有SharePoint对象模型和SharePoint数据库的必要权限。请按照this article设置使用PowerShell管理SharePoint的权限。
例如,要提供对所有内容数据库和SharePoint服务应用程序数据库的访问,可以使用以下命令:
Get-SPDatabase | Add-SPShellAdmin DOMAIN\username