Guest User

Untitled

a guest
Nov 20th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. write-output "" | out-file -filepath c:inventory.txt
  2.  
  3. Add-PSSnapin Microsoft.Sharepoint.Powershell
  4.  
  5. [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
  6. {
  7. $siteCollectionURL = "http://srvr1.company.com/sites/TestRC/"
  8. $siteColl = Get-SPSite $siteCollectionURL
  9. $doclibs = @("CB")
  10. $subFolder = @("folder1" , "folder2" ,"folder3" )
  11. Function GetFiles($Folder)
  12. {
  13. Write-Host "+"$Folder.Name
  14.  
  15. #Loop through all subfolders and call the function recursively
  16. foreach ($subFolder in $Folder.SubFolders)
  17. {
  18. if(($subFolder.Name -eq "Public") -Or ($subFolder.Name -eq "folder1") -Or ($subFolder.Name -eq "folder2" ))
  19. {
  20. Write-Host "`t" -NoNewline
  21. $Files = $subFolder. | where {$_.FileSystemObjectType -eq "File"} # here i am getting null value though items exist
  22. if($Files -eq $null)
  23. {
  24. Write-Host "+++++ There is no file in this subfolder " + $subFolder.Title
  25. Write-Output "+++++ There is no file in this subfolder " + $subFolder.Title | out-file -filepath c:inventory.txt -append
  26. }
  27. else
  28. {
  29. foreach ($file in $Files)
  30. {
  31. $itemFile = $file.File
  32. if( $itemFile.CheckOutStatus -ne "None" )
  33. {
  34. $itemFile.CheckIn("Automatic CheckIn.(Administrator)")
  35. }
  36.  
  37. Write-Host "+++++ Deleting file " $file.Name
  38. Write-Output "+++++ Deleting file " $file.Name | out-file -filepath c:inventory.txt -append
  39. $file.Delete()
  40. Write-Host "+++++ Done with Deleting file " $file.Name
  41. Write-Output "+++++ Done with Deleting file " $file.Name | out-file -filepath c:inventory.txt -append
  42. }
  43. }
  44. GetFiles($Subfolder)
  45. }
  46. }
  47. }
  48. if($siteColl -ne $null)
  49. {
  50. Write-Host "+ Site Collection : " $siteColl.Name
  51. Write-Output "+ Site Collection : " $siteColl.Name | out-file -filepath c:inventory.txt -append
  52. Write-Host "++ Site Collection : " $siteColl.Url
  53. foreach($subWeb in $siteColl.AllWebs)
  54. {
  55. if($subWeb -ne $null)
  56. {
  57. #Print each Subsite
  58. Write-Host "+++ Sub Web : " $subWeb.Url
  59. Write-Output "+++ Sub Web : " $subWeb.Url | out-file -filepath c:inventory.txt -append
  60.  
  61. # $Libraries = $subWeb.Lists | where {$_.BaseType -eq "DocumentLibrary"}
  62. foreach ($doclib in $doclibs)
  63. {
  64. $library = $subWeb.Lists[$doclib]
  65. Write-Host "++++ Getng files from library : " $library.Title
  66. Write-Output "++++ Getting files from library : " $library.Title | out-file -filepath c:inventory.txt -append
  67. #$Files = $library.Items | where {$_.FileSystemObjectType -eq "File"}
  68. GetFiles($library.RootFolder)
  69. }
  70. }
  71. # Write-host -ForegroundColor Red ("Items to be deleted : " + $subWeb.RecycleBin.Count.toString())
  72. # Write-Output ("Items to be deleted : " +$subWeb.RecycleBin.Count.toString()) | out-file -filepath c:inventory.txt -append
  73. # $now = Get-Date
  74. # Write-host -ForegroundColor Red ("Deleting started at " + $now.toString())
  75. # Write-Output ("Deleting started at " +$now.toString()) | out-file -filepath c:inventory.txt -append
  76. # if ($subWeb.RecycleBin.Count -ne $null)
  77. # {
  78. # $subWeb.RecycleBin.DeleteAll();
  79. # }
  80. # $now = Get-Date
  81. # write-host -ForegroundColor Red ("Deleting completed at " +$now.toString())
  82. # Write-Output ("Deleting completed at " +$now.toString()) | out-file -filepath c:inventory.txt -append
  83. $subWeb.Dispose()
  84. }
  85. else
  86. {
  87. Echo $subWeb "does not exist"
  88. }
  89. }
  90. # write-host $siteColl
  91. # write-host -ForegroundColor Red ("Items to be deleted : " +$siteColl.RecycleBin.Count.toString())
  92. # Write-Output ("Items to be deleted : " +$siteColl.RecycleBin.Count.toString()) | out-file -filepath c:inventory.txt -append
  93. # $now = Get-Date
  94. # write-host -ForegroundColor Red ("Deleting started at " +$now.toString())
  95. # Write-Output ("Deleting started at " +$now.toString()) | out-file -filepath c:inventory.txt -append
  96. # if ($siteColl.RecycleBin.Count -ne 0) {
  97. # $siteColl.RecycleBin.DeleteAll();
  98. # }
  99. });
Add Comment
Please, Sign In to add comment