我怎么能只导出扩展名为.mp4的文件?我目前正在导出文档库中的所有文件。
代码:我目前正在从视频库中提取所有项目。
# Add SharePoint Snapin to PowerShell # $_.extension -eq $FileExtension
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$web = Get-SPWeb "http://sourcevideo.f.com/"
$Data = foreach ($list in $web.Lists["Video"]) {
if ($list.BaseType -eq “DocumentLibrary”){
#if ($item -Like "*.mp4"){
foreach ($item in $list.Items) {
$data = @{
"List Name" = $list.Title
"Created By" = $item["Author"]
"Created Date" = $item["Created"]
"Modified By" = $item["Editor"]
"Modified Date" = $item["Modified"]
"Item Name" = $item.File.Name
"URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
}
New-Object PSObject -Property $data | Select "List Name", "Item Name", "Created By", "Created Date", "Modified By", "Modified Date", "URL"
#}
}
}
$web.Dispose()
}
$Data | Export-Csv C:\Users\ptadmin\Desktop\process9.csv -NoTypeInformation
答案 0 :(得分:1)
如果您只是想从目录中导出*.mp4
文件,只需执行以下操作:
$files = Get-ChildItem -Filter *.mp4
如果要在目录上递归执行此操作,
$files = Get-ChildItem -Recurse -Filter *.mp4
答案 1 :(得分:1)
您可以尝试这个。
# Add SharePoint Snapin to PowerShell # $_.extension -eq $FileExtension
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$web = Get-SPWeb "http://sp:12001/"
$Data = foreach ($list in $web.Lists["MyDoc"]) {
if ($list.BaseType -eq "DocumentLibrary"){
#if ($item -Like "*.mp4"){
foreach ($item in $list.Items) {
$fileExtension= $item.File.Name.Split('.')[1]
if($fileExtension -eq 'mp4'){
$data = @{
"List Name" = $list.Title
"Created By" = $item["Author"]
"Created Date" = $item["Created"]
"Modified By" = $item["Editor"]
"Modified Date" = $item["Modified"]
"Item Name" = $item.File.Name
"URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
}
New-Object PSObject -Property $data | Select "List Name", "Item Name", "Created By", "Created Date", "Modified By", "Modified Date", "URL"
#}
}
}
}
$web.Dispose()
}
$Data | Export-Csv C:\Lee\Script\process9.csv -NoTypeInformation