Deleting Multiple Files in DSC

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 year, 4 months ago.

  • Author
  • #64404

    Quintin Fulgham Jr

    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


    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?

  • #64410

    Don Jones

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

You must be logged in to reply to this topic.