Author Posts

February 16, 2017 at 3:40 pm

Hey Guys!

I was wondering if there was a way to delete multiple files in a directory, but not ALL the files. I know That with the dsc File resource you can delete the contents of a directory with the recurse=$true statement, but lets say I had 3 files in a directory named

file.txt
file.1.txt
file.2.txt

And I only wanted to delete the files with the numbers in them. I tried using this value in the DestinationPath:

DestinationPath = "C:\Users\******\Desktop\MISC\example_log_test_folder\file.txt.*"

But powershell returned thsi to me:

Wildcard characters are not supported in DestinationPath property.
+ CategoryInfo : NotImplemented: (:) [], CimException
+ FullyQualifiedErrorId : MI RESULT 7
+ PSComputerName : localhost

So I assume that powershell dsc doesnt recognize wildcards for manipulating multiple objects I think. So is there a way to delete multiple files with out having to declare a bunch of dsc statements?

February 16, 2017 at 3:42 pm

You'd need to do a custom resource, or a Script resource.