繁体   English   中英

如何通过Powershell显示项目并将其添加到Sharepoint列表?

[英]How I can show and add items to Sharepoint List via Powershell?

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

名称是Powershell-Test

网址是

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

我在Sharepoint Server上启用了remote,并从我的本地主机建立了远程连接。

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“] }

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

我该怎么办?

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

我还假定您没有名为“列表”的站点或子站点。

我认为您不能在其中使用路径为“ / Lists /”的Get-SPWeb(除非站点被命名为“ lists”)。

您可以尝试:

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"] }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM