Caveat: Cannot use Microsoft.SharePoint.Powershell
Snap-in.
I want create a PowerShell script that will search a SharePoint document library for the most recent file.
https://sharepoint.url.com/site/Your_Site_Name/Sub_Site/SharedDocuments/
I am trying to incorporate the Get-ChildItem
to search for the latest file.
Here is an example:
$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)
My problem is that when I run this script, I get the following error:
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
I am unable to use the UNC path on the server (Win 2012) I am using. I get "add site to 'trusted site' and try again, when I try to utilize 'Open with Explorer'.
\\sharepoint.url.com\site\your-site-name...
– Thriggle