【问题标题】:How to download file and store it in a folder using PowerShell in SharePoint?如何在 SharePoint 中使用 PowerShell 下载文件并将其存储在文件夹中?
【发布时间】:2017-08-15 05:10:49
【问题描述】:

目标是从 SharePoint 下载最新的 excel 文件并将其保存在本地文件夹中。 SharePoint 没有特定的文件名,但我们只需要下载最新的文件名,并将其保存到目标文件夹。我能够从 SharePoint 获取最新文件,但一直将文件写入本地磁盘。帮助表示赞赏。

从 SharePoint 获取最新文件名的 PS 脚本

$dir = "UNC Sharepoint folder"
$destinationfolder   = "C:\SharePoint\"
$filter="*.xlsx"
$latest = Get-ChildItem -Path $dir -Filter $filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name
$fl=$latest.Name
$fl

【问题讨论】:

    标签: powershell sharepoint


    【解决方案1】:

    这应该可行:

    Copy-Item (Join-Path $dir $fl) -Destination ($destinationfolder)
    

    [编辑]:减少行数 -

    $dir = "UNC Sharepoint folder"
    $destinationfolder   = "C:\sharepoint\"
    $filter="*.xlsx"
    Copy-Item (Join-Path $dir (Get-ChildItem -Path $dir -Filter $filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1)) -Destination ($destinationfolder)
    

    【讨论】:

      猜你喜欢
      • 2020-01-19
      • 1970-01-01
      • 2021-10-13
      • 2021-04-15
      • 2021-04-20
      • 2019-11-18
      • 1970-01-01
      • 2021-03-24
      • 2014-02-26
      相关资源
      最近更新 更多