Author Posts

November 9, 2013 at 6:23 am

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: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetChildItemCommand

November 9, 2013 at 6:25 am

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

Look into the -recurse parameter.

November 12, 2013 at 6:37 am

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