Get mutilple files ext using Get-ChildItem c:\*\*\*

Shall I get multiple files ext using the below command?

Get-ChildItem c:***

getting below error.
PS C:> $exts = “.txt”, “.evt”, “.jpg”, “.png”
PS C:> Get-ChildItem c:*** $exts
Get-ChildItem : Cannot convert ‘System.Object[]’ to the type ‘System.String’ required by parameter ‘Filter’. Specified
method is not supported.
At line:1 char:24

  • Get-ChildItem c:*** $exts
  •                    ~~~~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Get-ChildItem], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetChildItemCommand

No. The -Path parameter does not accept wildcards in that fashion.

Look into the -recurse parameter.

Don is correct in that you should check out the -recurse to look through the entire drive. You should also use -include to include only those file types you’re looking for.

Here’s an example of EXcluding certain file types from a search. (This particular script looks for and removes files older than 6 years, excluding certain file types)

The -Whatif at the end tells powershell to only simulate the command, and not actually remove any files. I generally use that when I am testing scripts that delete data.

$strDRV = Read-Host 'Enter Drive to Remove Aged Data From: Ex: C:\ '
Get-ChildItem $strDRV -exclude *.exe,*.mdb,*.dbf,*.ndx -recurse| where {!$_.PSIsContainer -and $_.Lastwritetime -lt (date).adddays(-2190)}|remove-item  -force -WhatIf