Hi
I’m trying to delete certain files from a Sharepoint folder, however no matter what I try, I cannot get it to delete. I have an exclusions list, for the names of pictures that should not be deleted. I have attached one of many tries, but without success. Anyone know what to do?
You haven’t provided enough information for anyone to help.
What’s the output of your Write-Host commands, is it what you would expect?
Does $items actually contain anything i.e. are there definitely files to process?
Are you getting any error messages?
Your method of looping over all the users is a bit clunky. $exclusions.User will be an array so you can just use the -contains or -notcontains operator and do away with the flag, for example:
foreach ($item in $itemList) {
if ($exclusions.User -notcontains $item.Name) {
$item.DeleteObject()
}
}
The Write-host commands prints out what pictures are to be deleted, and they work properly. The print out the name.jpg for each file, that should be deleted.
When using DeleteObject() there is not error messages, but the code executes and prints out the names of the pictures correctly.
Thank for the tip! I know the code is a bit scuffed, so it is highly appreciated!