Sharepoint 如何在库中查找文件(我是初学者)
我想使用powershell获取sharepoint库“EM_DOC_library”中的所有文件及其文件名。但是我完全不知道该怎么做,有人能帮我吗?将来,我们希望你至少检查一下谷歌,并尝试自己编写脚本。但我今天感觉有点利他。下面是一些代码,它应该为您指出正确的方向 另外,一定要查看更多PowerShell/SharePoint功夫 按ID获取特定列表项Sharepoint 如何在库中查找文件(我是初学者),sharepoint,powershell,powershell-2.0,Sharepoint,Powershell,Powershell 2.0,我想使用powershell获取sharepoint库“EM_DOC_library”中的所有文件及其文件名。但是我完全不知道该怎么做,有人能帮我吗?将来,我们希望你至少检查一下谷歌,并尝试自己编写脚本。但我今天感觉有点利他。下面是一些代码,它应该为您指出正确的方向 另外,一定要查看更多PowerShell/SharePoint功夫 按ID获取特定列表项 ## this is how you load the native SharePoint DLL to Powershell (On Ser
## 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场上获取大型文件
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
将来,我们希望你至少检查一下谷歌,并尝试自己编写脚本。但我今天感觉有点利他。下面是一些代码,它应该为您指出正确的方向 另外,一定要查看更多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场上获取大型文件
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(); }
这是您想要的轻量级脚本:
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抱歉,兄弟,我们不是来为你写代码的;)谷歌是你的朋友。@user1456899我同意Pixelboy。试着玩它。探索sharepoint对象模型。探索sharepoint cmdlet。(我编辑了我的答案以删除文件),但您仍然需要加载DLL<代码>[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)好的,谢谢,我忘了那一个。如果我说,我想找到带有“helloworld.psl”的文件并删除它,我该怎么写?(这是我的第一天工作,哈哈)@user1456899抱歉,兄弟,我们不是来为你写代码的;)谷歌是你的朋友。@user1456899我同意Pixelboy。试着玩它。探索sharepoint对象模型。探索sharepoint cmdlet。(我编辑了答案以删除文件)