stratoman
asked on
Delete files in a sharepoint library except one folder
I am trying to use a script. but i only want to delete files in the root of document library and not one specific folder. basically when the script runs, it looks at the library and delete all files except in a folder called Archive. I use below script but it also delete files in the Archive folder. Can someone help me?
$web = Get-SPWeb "my site"
$Libraries = $web.Lists | where {$_.Title -eq "Shared Documents" }
foreach ($library in $Libraries) {
Write-Output "Getting files from $($library.Title)"
$Files = $library.Items | where {$_.FileSystemObjectType -eq "File" -And ($_.File -Like "*.pdf" -Or $_.File -Like "*.docx" -Or $_.File -Like "*.doc")}
foreach ($file in $Files) {
Write-Output "Deleting file $($file.Name)..."
$file.Delete()
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
no problem.
It is not so easy to get all properties as each and every different property type can have additional/other properties.
But the MSDN object reference is really good and helpful - sometimes hard to navigate (I normally open new tabs and end up with at least 6-10 :-) )
http://msdn.microsoft.com/en-us/library/Microsoft.SharePoint.aspx
Thanks and HTH
Rainer
PS: Please do not forget to mark the question as answered.
no problem.
It is not so easy to get all properties as each and every different property type can have additional/other properties.
But the MSDN object reference is really good and helpful - sometimes hard to navigate (I normally open new tabs and end up with at least 6-10 :-) )
http://msdn.microsoft.com/en-us/library/Microsoft.SharePoint.aspx
Thanks and HTH
Rainer
PS: Please do not forget to mark the question as answered.
ASKER
Thanks again for the prompt reply!
ASKER
i have no words to describe how happy i am now. The script worked perfectly. and Thanks to you. I was looking for this File.ParentFolder.Name property and i just couldn't. how can i get all the properties of a library in sharepoint? Great help to me and thank you again!!!!!!!!!!!