Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get a Document URL via PowerShell & SharePoint Online

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I have roughly 1000 files located in SharePoint that I need to query to produce a report of file name and the URL for the file. We are using SharePoint Online and I have been testing with the PNP model.

My company has 2 Factor Authentication enabled, so I need to use the -UseWebLogin method to connect.

I have been able to retrieve document GUIDs in the library I want the URLs for, but have been unable to find a way to reverse engineer the URLs witht he GUID or any other properties. Has anyone else found a solution to this?

Here is what I have so far:
Code:
# Load References
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null


# Global Variables
$siteUrl = "[URL unfurl="true"]https://mytennant.sharepoint.com/sites/TechSupport/"[/URL]
$listName= "Tech Support Symptoms Index"

# Credentials
Connect-PnPOnline -Url $siteUrl -UseWebLogin

Write-Host "The script is now running. Please avoid exiting to prevent incomplete results." -ForegroundColor Cyan

# Get All List Items
$listItems = Get-PnPListItem -List $listName

# Traverse List Items
foreach ($item in $listItems)
{
    If($item.FieldValues.Domain = "TS Tandem OP")
    {
      $item.FieldValues.GUID.ToString()
    }
}

And the output the above produces output like this (truncated for brevity):
Code:
c5c8fd46-9c0d-4ccf-94a8-cb549cfc3796
09c88000-4c6d-48bc-a8f7-d838f608bde6
6fc15ac1-7b27-49ed-9e81-3de544df261a
e882724e-c04a-4c3a-973d-cbce4458bd2f
67d65189-7976-414f-bb3f-d788ad7ca7ff
9dc0689d-82ca-401b-8b19-dbac5fed5eaa
29284cba-3449-4443-9626-c18662ca9980
ea486235-99f9-43c2-85c9-29964646d0ba
2a39cdeb-70f7-4763-abb4-498d25ea5b34
aed593a5-fe10-44af-b231-f84eebfd52e5
d9884e82-1436-44f8-9723-adb70b22435e

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top