【发布时间】:2012-06-23 20:33:04
【问题描述】:
我想使用 powershell 来获取共享点库“EM_DOC_LIBRARY”中的所有文件及其文件名。但是我完全不知道该怎么做,有人可以帮助我吗?
【问题讨论】:
标签: sharepoint powershell powershell-2.0
我想使用 powershell 来获取共享点库“EM_DOC_LIBRARY”中的所有文件及其文件名。但是我完全不知道该怎么做,有人可以帮助我吗?
【问题讨论】:
标签: sharepoint powershell powershell-2.0
将来,我们希望您至少检查一下 Google 并尝试自己编写脚本。但我今天感觉有点无私。这里有一些代码应该可以为您指明正确的方向...
另外,一定要查看Hey Scripting Guy's Blog 了解更多 PowerShell / SharePoint 功夫。
按 ID 获取特定列表项
## this is how you load the native SharePoint DLL to Powershell (On Server)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$url = “http://mysite.myurl.com”
$listName = "EM_DOC_LIBRARY"
$site = New-Object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
$list = $web.Lists[$listName]
$listitem = $web.Lists[$listName].Items.GetItemByID($litem)
更多示例代码 |在 SharePoint Farm 上获取大文件
function Get-DocInventory() {
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
foreach ($spService in $farm.Services) {
if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
continue;
}
foreach ($webApp in $spService.WebApplications) {
if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }
foreach ($site in $webApp.Sites) {
foreach ($web in $site.AllWebs) {
foreach ($list in $web.Lists) {
if ($list.BaseType -ne "DocumentLibrary") {
continue
}
foreach ($item in $list.Items) {
$data = @{
"Web Application" = $webApp.ToString()
"Site" = $site.Url
"Web" = $web.Url
"list" = $list.Title
"Item ID" = $item.ID
"Item URL" = $item.Url
"Item Title" = $item.Title
"Item Created" = $item["Created"]
"Item Modified" = $item["Modified"]
"Size (kb)" = $item.File.Length/1KB
"Size (gb)" = $item.File.Length/1GB
}
Write-Host $item.Url -ForegroundColor DarkGray
# Only add files larger than 100 MB
if($item.File.Length -gt 100MB){
Write-Host $site.Url + $item.Url -ForegroundColor Red
New-Object PSObject -Property $data
}
}
}
$web.Dispose();
}
$site.Dispose()
}
}
}
}
#Get-DocInventory | Out-GridView
Get-DocInventory | Export-Csv -NoTypeInformation -Path D:\Logs\inventory.csv
【讨论】:
这是你想要的轻量级脚本:
Add-PSSnapin Microsoft.Sharepoint.Powershell
$web = Get-SPWeb http://servername/subweb
$l = $web.Lists["EM_DOC_LIBRARY"]
$l.Items | ? { $_.Name -eq "yourfilename.txt" } | %{ $item = $l.GetItemByID($_.ID); $item.Delete(); }
【讨论】:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")