【问题标题】:Export only .mp4 file extensions using PowerShell使用 PowerShell 仅导出 .mp4 文件扩展名
【发布时间】:2019-06-11 00:24:58
【问题描述】:

我怎样才能只导出具有 .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

【问题讨论】:

    标签: shell powershell sharepoint powershell-2.0


    【解决方案1】:

    如果您只是想从目录中导出 *.mp4 文件,只需执行以下操作:

    $files = Get-ChildItem -Filter *.mp4
    

    如果您想在目录上递归地执行此操作,

    $files = Get-ChildItem -Recurse -Filter *.mp4
    

    【讨论】:

      【解决方案2】:

      你可以试试这个。

      # 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
      

      【讨论】:

      • 我会将$fileExtension= $item.File.Name.Split('.')[1] 更改为$fileExtension= $item.File.Name.Split('.')[-1] 以确保您获得最后一个元素。否则,如果文件名为abc.def.mp4,则执行$fileExtension= $item.File.Name.Split('.')[1] 将返回def
      猜你喜欢
      • 2020-02-16
      • 1970-01-01
      • 2023-03-23
      • 2020-05-28
      • 1970-01-01
      • 2012-04-05
      • 2016-07-08
      • 1970-01-01
      • 2020-03-11
      相关资源
      最近更新 更多