SharePoint Online: PowerShell เพื่อตรวจสอบเอกสารทั้งหมดจำนวนมาก
ความต้องการ: ตรวจสอบเอกสารทั้งหมดใน SharePoint Online จำนวนมากโดยใช้ PowerShell
จะตรวจสอบเอกสารจำนวนมากใน SharePoint Online ได้อย่างไร
ใน SharePoint Online เอกสารที่อัปโหลดไปยังไลบรารีเอกสารสามารถเช็คเอาท์ได้เพื่อป้องกันไม่ให้ผู้ใช้หลายคนทำการเปลี่ยนแปลงในเวลาเดียวกัน เมื่อผู้ใช้แก้ไขเสร็จแล้ว พวกเขาควรเช็คอินอีกครั้ง เอกสารที่เช็คเอาท์อาจทำให้เกิดปัญหาและป้องกันไม่ให้ผู้ใช้รายอื่นเข้าถึงและแก้ไขเอกสารเหล่านั้นหากไม่ได้เช็คอินอีกครั้ง
อาจมีบางครั้งที่คุณต้องตรวจสอบเอกสารจำนวนมากใน SharePoint Online จะตรวจสอบเอกสารหลายฉบับใน SharePoint Online ได้อย่างไร คุณสามารถตรวจสอบไฟล์เดียวหรือหลายไฟล์ในไลบรารีเอกสารได้โดยเลือกไฟล์เหล่านั้นแล้วเลือก "เช็คอิน" ภายในไม่กี่คลิก
เอกสารที่เลือกจะถูกเช็คอินและพร้อมให้ผู้ใช้รายอื่นเข้าถึงและแก้ไขได้
ตรวจสอบหลายไฟล์จำนวนมากใน SharePoint Online
ลองเช็คอินไฟล์ทั้งหมดในไลบรารีเอกสารดูไหม? เรามีไลบรารีเอกสารพร้อมโฟลเดอร์และโฟลเดอร์ย่อยที่มีเอกสารจำนวนมากที่เช็คเอาท์ เราต้องการเช็คอินและให้บริการแก่ผู้ใช้ปลายทาง ต่อไปนี้เป็นวิธีสร้างมุมมองเพื่อดูไฟล์ที่เช็คเอาท์ทั้งหมดในไลบรารี:
- นำทางไปยังไลบรารีเอกสารของคุณ >> คลิกที่เฟืองการตั้งค่า >> เลือกการตั้งค่าไลบรารี
- ในส่วน "มุมมอง" ให้สร้างมุมมองใหม่ รวมคอลัมน์ "เช็คเอาต์ไปยัง" ไว้ในมุมมอง
- ตั้งค่าลำดับ "จัดเรียง" ของมุมมองเป็นคอลัมน์ "เช็คเอาต์ไปยัง" ตามลำดับจากมากไปน้อย
- ในส่วน "โฟลเดอร์" ให้ตั้งค่า "แสดงรายการทั้งหมดที่ไม่มีโฟลเดอร์"
มุมมองนี้จะแสดงรายการไฟล์ที่เช็คเอาท์ทั้งหมดที่อยู่ด้านบน! คุณสามารถดูหรือเช็คอินเป็นกลุ่มได้
ด้วยการทำตามขั้นตอนง่ายๆ เหล่านี้ คุณสามารถเช็คอินไฟล์ที่เช็คเอาท์ทั้งหมดในไลบรารีเอกสาร SharePoint Online ของคุณได้ อย่างไรก็ตาม ในไลบรารีเอกสารขนาดใหญ่ที่มีเอกสารจำนวนมากที่เช็คเอาท์ ฉันพยายามสร้างมุมมองที่กรองไฟล์ที่เช็คเอาท์ทั้งหมด แต่ล้มเหลวเนื่องจากจำนวนรายการคือ > 5000 (ปัญหาขีดจำกัดมุมมองรายการ!) ลองใช้ PowerShell เพื่อตรวจสอบไฟล์ทั้งหมดใน SharePoint กันดีกว่า
SharePoint Online: PowerShell เพื่อตรวจสอบเอกสารทั้งหมด
คุณจำเป็นต้องเช็คอินไฟล์จำนวนมากพร้อมกันใน SharePoint Online หรือไม่ หากเป็นเช่นนั้น PowerShell สามารถช่วยได้ นี่คือ PowerShell สำหรับตรวจสอบไฟล์หลายไฟล์ในไลบรารีเอกสาร SharePoint Online:
#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"
#Set parameters
$SiteURL="https://crescent.sharepoint.com"
$LibraryName="Shared Documents"
Try{
#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
$Web = $Ctx.Web
$Ctx.Load($Web)
$List = $Web.Lists.GetByTitle($LibraryName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Prepare the query
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "@
<View Scope='RecursiveAll'>
<Query>
<OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
</Query>
<RowLimit Paged='TRUE'>2000</RowLimit>
</View>"
$Counter=1
#Batch Process items: sharepoint online powershell bulk check in
Do {
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
#Get All Checked out files
ForEach($Item in $ListItems | Where {$_.FileSystemObjectType -eq "File"})
{
#Display a Progress bar
Write-Progress -Activity "Scanning Files in the Library" -Status "Testing if the file is Checked-Out '$($Item.FieldValues.FileRef)' ($Counter of $($List.ItemCount))" -PercentComplete (($Counter / $List.ItemCount) * 100)
#Get the Checked out File data
$File = $Ctx.Web.GetFileByServerRelativeUrl($Item["FileRef"])
$Ctx.Load($File)
$CheckedOutByUser = $File.CheckedOutByUser
$Ctx.Load($CheckedOutByUser)
$Ctx.ExecuteQuery()
If($File.Level -eq "Checkout")
{
Write-Host -f Yellow "Found a Checked out File '$($File.Name)' at $($Web.url)$($Item['FileRef']), Checked Out By: $($CheckedOutByUser.LoginName)"
#Check in the document
$File.CheckIn("Checked-in By Administrator through PowerShell!", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
$Ctx.ExecuteQuery()
Write-Host -f Green "File '$($File.Name)' Checked-In Successfully!"
}
$Counter++
}
}While($Query.ListItemCollectionPosition -ne $Null)
}
Catch {
write-host -f Red "Error Check In Files!" $_.Exception.Message
}
SharePoint Online: เช็คอินหลายไฟล์โดยใช้ PowerShell
คุณกำลังพยายามตรวจสอบไฟล์ทั้งหมดที่บุคคลอื่นเช็คเอาท์ในปัจจุบันหรือไม่? มาสแกนคอลเลกชันไซต์ทั้งหมดเพื่อหาไฟล์ที่เช็คเอาท์แล้วเช็คอินกลับโดยใช้ 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"
#PowerShell to Bulk check-in all documents
Function CheckIn-AllDocuments([String]$SiteURL)
{
Try{
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.Load($Web.Webs)
$Ctx.ExecuteQuery()
#Get All Lists from the web
$Lists = $Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()
#Prepare the CAML query
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "@
<View Scope='RecursiveAll'>
<Query>
<OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
</Query>
<RowLimit Paged='TRUE'>2000</RowLimit>
</View>"
#Array to hold Checked out files
$CheckedOutFiles = @()
Write-host -f Yellow "Processing Web:"$Web.Url
#Iterate through each document library on the web
ForEach($List in ($Lists | Where-Object {$_.BaseTemplate -eq 101 -and $_.Hidden -eq $False -and $_.ItemCount -gt 0}) )
{
Write-host -f Yellow "`t Processing Document Library:"$List.Title
$Counter=1
#Batch Process List items
Do {
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
#Get All Checked out files
ForEach($Item in $ListItems | Where {$_.FileSystemObjectType -eq "File"})
{
#Display a Progress bar
Write-Progress -Activity "Scanning Files in the Library" -Status "Testing if the file is Checked-Out '$($Item.FieldValues.FileRef)' ($Counter of $($List.ItemCount))" -PercentComplete (($Counter / $List.ItemCount) * 100)
Try{
#Get the Checked out File data
$File = $Web.GetFileByServerRelativeUrl($Item["FileRef"])
$Ctx.Load($File)
$CheckedOutByUser = $File.CheckedOutByUser
$Ctx.Load($CheckedOutByUser)
$Ctx.ExecuteQuery()
If($File.Level -eq "Checkout")
{
Write-Host -f Green "`t`t Found a Checked out File '$($File.Name)' at $($Item['FileRef']), Checked Out By: $($CheckedOutByUser.LoginName)"
#Check in the document
$File.CheckIn("Checked-in By Administrator through PowerShell!", [Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)
$Ctx.ExecuteQuery()
Write-Host -f Green "`t`t File '$($File.Name)' Checked-In Successfully!"
}
}
Catch {
write-host -f Red "Error Check In: $($Item['FileRef'])" $_.Exception.Message
}
$Counter++
}
}While($Query.ListItemCollectionPosition -ne $Null)
}
#Iterate through each subsite of the current web and call the function recursively
ForEach($Subweb in $Web.Webs)
{
#Call the function recursively to process all subsites underneath the current web
CheckIn-AllDocuments -SiteURL $Subweb.URL
}
}
Catch {
write-host -f Red "Error Bulk Check In Files!" $_.Exception.Message
}
}
#Config Parameters
$SiteURL="https://crescent.sharepoint.com/Sites/Marketing"
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Call the function: sharepoint online powershell to check in all documents in a Site Collection
CheckIn-AllDocuments -SiteURL $SiteURL
หากคุณต้องการเช็คอินไฟล์ใน SharePoint Online ให้ใช้: PowerShell เพื่อเช็คอินเอกสารใน SharePoint Online
PnP PowerShell เพื่อเช็คอินไฟล์ทั้งหมดในไลบรารีเอกสาร
ต่อไปนี้เป็นวิธีใช้ PnP PowerShell เพื่อตรวจสอบเอกสารทั้งหมดในไลบรารีเอกสาร SharePoint Online:
#Parameter
$SiteURL= "https://crescent.sharepoint.com/sites/marketing/"
$ListName = "Documents"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get All List Items from the List - Filter Files
$ListItems = Get-PnPListItem -List $ListName -PageSize 500 | Where {$_["FileLeafRef"] -like "*.*"}
#Loop through each list item
ForEach ($Item in $ListItems)
{
Write-host -f Yellow "Testing If file is Checked-Out:"$Item.FieldValues["FileRef"]
#Get the File from List Item
$File = Get-PnPProperty -ClientObject $Item -Property File
If($File.Level -eq "Checkout")
{
#Check-In and Approve the File
Set-PnPFileCheckedIn -Url $File.ServerRelativeUrl -CheckinType MajorCheckIn
Write-host -f Green "`tFile Checked-In:"$File.ServerRelativeUrl
}
}
โดยสรุป การใช้สคริปต์ PowerShell เพื่อเช็คอินไฟล์จำนวนมากใน SharePoint Online เป็นวิธีที่ง่ายและมีประสิทธิภาพในการประหยัดเวลาและแรงงาน การทำตามขั้นตอนเหล่านี้จะช่วยให้คุณสามารถตรวจสอบเอกสารหลายฉบับใน SharePoint Online และป้องกันปัญหาการทำงานร่วมกันและการเข้าถึงได้

