如何通过Powershell向Sharepoint List显示和添加项目?

时间:2014-05-19 09:46:36

标签: list powershell sharepoint-2010 intranet powershell-remoting

嗨我想通过Powershell在Sharepoint中显示和添加项目(我用于测试列表和库)

名称为Powershell-Test

网址

http//intranet/departments/it/abt/Lists/Powershell-Test/AllItems.aspx

我在Sharepoint Server上启用了remote,并从我的localhost远程连接到该端口。

Enter-PSSession -ComputerName [sharepoint server] -Authentication Negotiate -Credential [Domain\name]

if((Get-PSSnapin -Name Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin Microsoft.Sharepoint.Powershell
}

$webURL = "http//intranet/departments/it/abt/Lists/"
$listname = "Powershell-Test"

$web = Get-SPWeb $webURL

$web.lists | format-table title 

$list = $web.LIsts[$listName]

$list.items | foreach { $_[„Title“] + „`n“ + $_[„Body“] }

问题是我没有得到与列表的连接:(

我怎么能这样呢?

1 个答案:

答案 0 :(得分:0)

我认为您有权访问该网站。

我还假设您没有名为“Lists”的网站或子网站。

我认为您不能使用Get-SPWeb并在其中包含“/ Lists /”路径(除非该网站被命名为“list”)。

你可以尝试一下:

if ((Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.Powershell 
}

$siteURL = "http//intranet/departments/it/abt/"
$web = Get-SPWeb $siteURL
$list = $web.Lists["Powershell-Test"]
$list.Items | foreach { $_["Title"] + "`n" + $_["Body"] }