Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 从SharePoint文档库下载最新文件_Powershell_Sharepoint - Fatal编程技术网

Powershell 从SharePoint文档库下载最新文件

Powershell 从SharePoint文档库下载最新文件,powershell,sharepoint,Powershell,Sharepoint,警告:无法使用Microsoft.SharePoint.Powershell管理单元 我希望创建一个PowerShell脚本,用于在SharePoint文档库中搜索最新文件 我正在尝试合并Get ChildItem以搜索最新的文件 以下是一个例子: $fromfile = "https://sharepoint.url.com/site/Your_Site_Name/Sub_Site/SharedDocuments/File_name*" $tofile = "c:\temp\temp_fi

警告:无法使用Microsoft.SharePoint.Powershell管理单元

我希望创建一个PowerShell脚本,用于在SharePoint文档库中搜索最新文件

我正在尝试合并Get ChildItem以搜索最新的文件

以下是一个例子:

$fromfile = "https://sharepoint.url.com/site/Your_Site_Name/Sub_Site/SharedDocuments/File_name*"
$tofile   = "c:\temp\temp_file.xlsx"

$latest = Get-ChildItem -Path $fromfile | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name

$webclient = New-Object System.Net.WebClient

$webclient.UseDefaultCredentials = $true

$webclient.DownloadFile($latest.name, $tofile)
我的问题是,运行此脚本时,出现以下错误:

Get-ChildItem : Cannot find drive. A drive with the name 'https' does not exist.
At line:4 char:11
+ $latest = Get-ChildItem -Path $fromfile | Sort-Object LastAccessTime

我无法使用正在使用的服务器Win 2012上的UNC路径。当我尝试使用“使用资源管理器打开”时,我会将站点添加到“受信任的站点”并重试。

我有一个与您类似的要求,但我首先从映射SharePoint UNC路径开始。问题是它并不总是能立即找到,因此可能需要重试几次:

$SharePoint  = '\\xxx.domain.net\site\Documents'
$LocalDrive  = 'S:'
$Credentials = Get-Credential


if (!(Test-Path $LocalDrive -PathType Container)) {
    $retrycount = 0; $completed = $false
    while (-not $completed) {
        Try {
            if (!(Test-Path $LocalDrive -PathType Container)) {
                (New-Object -ComObject WScript.Network).MapNetworkDrive($LocalDrive,$SharePoint,$false,$($Credentials.username),$($Credentials.GetNetworkCredential().password))
            }
            $Completed = $true
        }
        Catch {
            if ($retrycount -ge '5') {
                Write-Verbose "Mapping SharePoint drive failed the maximum number of times"
                throw "SharePoint drive mapping failed for '$($SharePoint)': $($Global:Error[0].Exception.Message)"
            } else {
                Write-Verbose "Mapping SharePoint drive failed, retrying in 5 seconds."
                Start-Sleep '5'
                $retrycount++
            }
        }
    }
}
映射SharePoint文档库后,可以使用所需的所有cmdlet筛选出要查找的文件Get ChildItem S:\

如何找到UNC路径

通过在浏览器中打开站点,查看所有站点内容,单击“文档”,然后选择“操作”并使用Windows资源管理器打开。地址栏中的链接就是您需要的链接


您的问题是…?您是否尝试过使用UNC文件路径而不是web地址?例如:\\sharepoint.url.com\site\your site name…在我运行PowerShell的服务器上,当我尝试获取UNC路径时,会得到“将此网站添加到您的受信任网站并重试”。我会添加它,但我仍然会收到相同的消息。嗯。。我们只是想映射一个驱动器,不需要可信的站点。在运行框Win+R中粘贴UNC路径并单击“确定”时,是否会打开文档库?如果您使用的是Win Srv 2012,则需要通过运行install WindowsFeature Desktop experience来安装桌面体验。还要确保您的用户$凭据对文档库具有权限。