با استفاده از اسکریپت زیر میتوانید تمامی فایلهای یک کتابخانه اسناد را حذف کنید.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Function to Delete all files in a Folder Function Delete-AllFilesFromLibrary([Microsoft.SharePoint.SPFolder]$Folder) { #Delete All Files in the Folder Foreach ($File in @($Folder.Files)) { #Delete the file $File.Delete() | Out-Null Write-host -f Green "Deleted File '$($File.Name)' from '$($File.ServerRelativeURL)'" } #Delete files in Sub-folders Foreach ($SubFolder in $Folder.SubFolders | where {$_.Name -ne "Forms"}) { #Call the function recursively Delete-AllFilesFromLibrary($SubFolder) } #Delete folders ForEach ($SubFolder in @($Folder.SubFolders)) { #Exclude "Forms" and Hidden folders If(($SubFolder.Name -ne "Forms") -and (-Not($SubFolder.Name.StartsWith("_")))) { #Delete the Sub-Folder $SubFolder.Delete() | Out-Null Write-host -f Green "Deleted Folder '$($SubFolder.Name)' from '$($SubFolder.ServerRelativeUrl)'" } } } #Get the Web and Library $Web = Get-SPWeb "http://intranet.drsharepoint.ir/sales" $Library = $Web.Lists.TryGetList("Documents") #Call the function to Delete all files in the Library Delete-AllFilesFromLibrary $Library.RootFolder
حذف تمامی فایلها و فولدرهای یک کتابخانه اسناد
1 دانلود- فرمت : Powershell
- حجم : 2KB
- محتوا : اسکریپت پاورشل
- نویسنده : سلین سرکیسیان
قطعه کد بالا تمامی فایلها و فولدرهای داخل یک کتابخانه اسناد را حذف میکند. ولی اگر بخواهید تنها فایلهای root حذف شوند و فولدرها حذف نشوند، میتوانید از قطعه کد زیر استفاده کنید.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Function to Delete all files in a Folder Function Delete-AllFilesFromLibrary([Microsoft.SharePoint.SPFolder]$Folder) { #Delete All Files in the Folder Foreach ($File in @($Folder.Files)) { #Delete the file $File.Recycle() | Out-Null Write-host -f Green "Deleted File '$($File.Name)' from '$($File.ServerRelativeURL)'" } #Delete files in Sub-folders Foreach ($SubFolder in $Folder.SubFolders | where {$_.Name -ne "Forms"}) { #Call the function recursively Delete-AllFilesFromLibrary($SubFolder) } } #Get the Web and Library $Web = Get-SPWeb "http://intranet.drsharepoint.ir/sales" $Library = $Web.Lists.TryGetList("Documents") #Call the function to Delete all files in the Library Delete-AllFilesFromLibrary $Library.RootFolder
حذف تمامی فایلها در مسیر اصلی یک کتابخانه اسناد
1 دانلود- فرمت : Powershell
- حجم : 2KB
- محتوا : اسکریپت پاورشل
- نویسنده : سلین سرکیسیان