Deleting Multiple Files in DSC

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 3 months, 1 week ago.

  • Author
    Posts
  • #64404
    Profile photo of Quintin Fulgham Jr
    Quintin Fulgham Jr
    Participant

    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?

  • #64410
    Profile photo of Don Jones
    Don Jones
    Keymaster

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

You must be logged in to reply to this topic.