我想使用 powershell 来获取共享点库“EM_DOC_LIBRARY”中的所有文件及其文件名。但是我完全不知道如何做到这一点,有人可以帮助我吗?
问问题
6904 次
2 回答
3
将来,我们希望您至少检查一下 Google 并尝试自己编写脚本。但我今天感觉有点无私。这是一些应该为您指明正确方向的代码...
另外,一定要查看Hey Scripting Guy 的博客,了解更多 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
于 2012-06-21T15:03:50.403 回答
2
这是您想要的轻量级脚本:
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(); }
于 2012-06-21T15:09:35.683 回答