Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- write-output "" | out-file -filepath c:inventory.txt
- Add-PSSnapin Microsoft.Sharepoint.Powershell
- [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
- {
- $siteCollectionURL = "http://srvr1.company.com/sites/TestRC/"
- $siteColl = Get-SPSite $siteCollectionURL
- $doclibs = @("CB")
- $subFolder = @("folder1" , "folder2" ,"folder3" )
- Function GetFiles($Folder)
- {
- Write-Host "+"$Folder.Name
- #Loop through all subfolders and call the function recursively
- foreach ($subFolder in $Folder.SubFolders)
- {
- if(($subFolder.Name -eq "Public") -Or ($subFolder.Name -eq "folder1") -Or ($subFolder.Name -eq "folder2" ))
- {
- Write-Host "`t" -NoNewline
- $Files = $subFolder. | where {$_.FileSystemObjectType -eq "File"} # here i am getting null value though items exist
- if($Files -eq $null)
- {
- Write-Host "+++++ There is no file in this subfolder " + $subFolder.Title
- Write-Output "+++++ There is no file in this subfolder " + $subFolder.Title | out-file -filepath c:inventory.txt -append
- }
- else
- {
- foreach ($file in $Files)
- {
- $itemFile = $file.File
- if( $itemFile.CheckOutStatus -ne "None" )
- {
- $itemFile.CheckIn("Automatic CheckIn.(Administrator)")
- }
- Write-Host "+++++ Deleting file " $file.Name
- Write-Output "+++++ Deleting file " $file.Name | out-file -filepath c:inventory.txt -append
- $file.Delete()
- Write-Host "+++++ Done with Deleting file " $file.Name
- Write-Output "+++++ Done with Deleting file " $file.Name | out-file -filepath c:inventory.txt -append
- }
- }
- GetFiles($Subfolder)
- }
- }
- }
- if($siteColl -ne $null)
- {
- Write-Host "+ Site Collection : " $siteColl.Name
- Write-Output "+ Site Collection : " $siteColl.Name | out-file -filepath c:inventory.txt -append
- Write-Host "++ Site Collection : " $siteColl.Url
- foreach($subWeb in $siteColl.AllWebs)
- {
- if($subWeb -ne $null)
- {
- #Print each Subsite
- Write-Host "+++ Sub Web : " $subWeb.Url
- Write-Output "+++ Sub Web : " $subWeb.Url | out-file -filepath c:inventory.txt -append
- # $Libraries = $subWeb.Lists | where {$_.BaseType -eq "DocumentLibrary"}
- foreach ($doclib in $doclibs)
- {
- $library = $subWeb.Lists[$doclib]
- Write-Host "++++ Getng files from library : " $library.Title
- Write-Output "++++ Getting files from library : " $library.Title | out-file -filepath c:inventory.txt -append
- #$Files = $library.Items | where {$_.FileSystemObjectType -eq "File"}
- GetFiles($library.RootFolder)
- }
- }
- # Write-host -ForegroundColor Red ("Items to be deleted : " + $subWeb.RecycleBin.Count.toString())
- # Write-Output ("Items to be deleted : " +$subWeb.RecycleBin.Count.toString()) | out-file -filepath c:inventory.txt -append
- # $now = Get-Date
- # Write-host -ForegroundColor Red ("Deleting started at " + $now.toString())
- # Write-Output ("Deleting started at " +$now.toString()) | out-file -filepath c:inventory.txt -append
- # if ($subWeb.RecycleBin.Count -ne $null)
- # {
- # $subWeb.RecycleBin.DeleteAll();
- # }
- # $now = Get-Date
- # write-host -ForegroundColor Red ("Deleting completed at " +$now.toString())
- # Write-Output ("Deleting completed at " +$now.toString()) | out-file -filepath c:inventory.txt -append
- $subWeb.Dispose()
- }
- else
- {
- Echo $subWeb "does not exist"
- }
- }
- # write-host $siteColl
- # write-host -ForegroundColor Red ("Items to be deleted : " +$siteColl.RecycleBin.Count.toString())
- # Write-Output ("Items to be deleted : " +$siteColl.RecycleBin.Count.toString()) | out-file -filepath c:inventory.txt -append
- # $now = Get-Date
- # write-host -ForegroundColor Red ("Deleting started at " +$now.toString())
- # Write-Output ("Deleting started at " +$now.toString()) | out-file -filepath c:inventory.txt -append
- # if ($siteColl.RecycleBin.Count -ne 0) {
- # $siteColl.RecycleBin.DeleteAll();
- # }
- });
Add Comment
Please, Sign In to add comment