The script should delete the old files(files which are older than 30 days) from the server, and it should exclude those files whose name is starting with Evo.shibb.* and Hobsons.Platform.* and Shibboleth.*
It must delete only those files, whose name starts with connect.
I’m not sure what you mean by “it must only delete those files whose name starts with connect.” None of the exclusions you list start with “connect”, so do you want to exclude “Evo.shibb*”, “Hobsons.Platform*”, “Shibboleth*” or only delete “connect*”. Either way the approach is the same. Use get-childitem with the -exclude or -include switch depending on what you want to do, then pipe it to where-object and filter for only files older than 30 days, finally pipe that to remove-item. I would first use -whatif switch on remove-item before -force so you can be sure it is working as expected and not removing files you don’t want to. The -whatif will only output text telling you what would happen if you ran the command. Here is an example:
In powershell, if there’s no * in the path (or no -recurse), using both -exclude and -filter will prevent any files from being listed. I consider this a bug. It still exists in PS 6 (actually not in 6.1pr2) . Beginners often catch these things. -include will have the same effect as -filter.
i just wanted to exclude those mentioned 3 files and also i wanted to delete only “connect.12.1.nukpg” (file name with some no. with nupkg extension), may be the approach is same instead of excluding those 3 files, i think we can directly include Connect related files and delete them. but still i need the script in that way as i mentioned, i was trying to do that, i didn’t get exact script.
In that folder or path there will be lot many files with different extension and filenames will starts with different names.
i hope you got my point !! please help me on this.