1

The following works


Remove-Item *.xml, *.thm, *.bbl, *.fff

But this does not

$cleanExtensions = "*.xml, *.thm, *.bbl, *.fff"

Remove-Item $cleanExtensions

How can I let Remove-Item accept a variable list of items to remove?

1
  • 4
    your list is not a list ... it is a string. [grin] make it into a list/array/collection and it will work since the cmdlet in question will accept an array of items for that default parameter. Commented Sep 28, 2019 at 15:38

1 Answer 1

2

On the first option you are passing a list, while in the second one you are passing a string

Use the following notation to make your variable a list instead of a string

$cleanExtensions = "*.xml" , "*.thm", "*.bbl", "*.fff"
Remove-Item $cleanExtensions
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, but more accurately the "list" is an array, namely of type [object[]].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.