SharePoint Online: PowerShell เพื่อรับ URL รายการ
ข้อกำหนด: PowerShell เพื่อรับ URL รายการ SharePoint Online
SharePoint Online PowerShell เพื่อรับ URL รายการ
อาจมีบางครั้งที่คุณต้องการรับ URL ของรายการ SharePoint Online หรือไลบรารีเอกสาร โพสต์ในบล็อกนี้จะแสดงวิธีใช้ PowerShell เพื่อรับ URL ของรายการใน SharePoint Online
ต่อไปนี้เป็นวิธีรับ URL รายการใน SharePoint Online ด้วย PowerShell:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$ListName = "Documents"
#Get Credentials to connect
$Cred = Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Web and List Objects
$Web = $Ctx.Web
$Ctx.Load($Web)
$List = $Web.Lists.GetByTitle($ListName)
$Ctx.Load($List.RootFolder)
$Ctx.ExecuteQuery()
#List Relative URL
Write-host "List Relative URL:"$List.RootFolder.ServerRelativeUrl
#Get List Full URL
If($Ctx.Web.ServerRelativeUrl -eq "/")
{
$ListURL = $("{0}{1}" -f $Ctx.Web.Url, $List.RootFolder.ServerRelativeUrl)
}
Else
{
$ListURL = $("{0}{1}" -f $Ctx.Web.Url.Replace($Ctx.Web.ServerRelativeUrl,''), $List.RootFolder.ServerRelativeUrl)
}
Write-host "List Full URL:"$ListURL
PnP PowerShell เพื่อรับ URL ที่สมบูรณ์ของรายการใน SharePoint Online
เราสามารถรับ URL แบบเต็มของรายการหรือไลบรารีใน SharePoint Online ได้โดยใช้ PnP PowerShell เป็น:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/pmo"
$ListName= "Projects"
#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -Interactive
Try {
#Get the List
$List = Get-PnPList $ListName -Includes ParentWeb -ThrowExceptionIfListNotFound -ErrorAction Stop
#Get the absolute URL of the List
If($List.ParentWeb.ServerRelativeUrl -eq "/")
{
$ListURL = [String]::Concat($List.ParentWeb.Url,$List.DefaultViewUrl)
}
Else
{
$ListURL = [String]::Concat( $List.ParentWeb.Url,$List.DefaultViewUrl.Replace($List.ParentWeb.ServerRelativeUrl,[string]::Empty))
}
Write-host $ListURL
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}