【问题标题】:how to find files in a library(I'm a starter) [closed]如何在库中查找文件(我是初学者)[关闭]
【发布时间】:2012-06-23 20:33:04
【问题描述】:

我想使用 powershell 来获取共享点库“EM_DOC_LIBRARY”中的所有文件及其文件名。但是我完全不知道该怎么做,有人可以帮助我吗?

【问题讨论】:

    标签: sharepoint powershell powershell-2.0


    【解决方案1】:

    将来,我们希望您至少检查一下 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
    

    【讨论】:

      【解决方案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(); } 
      

      【讨论】:

      • 但您仍然需要加载 DLL...[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
      • 好的,谢谢,我忘记了。
      • 所以如果我说,我想找到带有“helloworld.psl”的文件并删除它,我该怎么写?(这是我的第一天工作,哈哈)
      • @user1456899 抱歉,兄弟,我们不是来为你编写代码的;)但是,Google 是你的朋友。
      • @user1456899 我同意 pixelbobby。尝试玩它。探索共享点对象模型。探索 sharepoint cmdlet。 (我编辑了我的答案以删除文件)
      猜你喜欢
      • 2017-02-05
      • 2011-12-12
      • 2013-08-19
      • 2011-03-17
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 2019-10-10
      • 1970-01-01
      相关资源
      最近更新 更多