Config value:
<FileTypesToDelete>*.txt,*.log,*.mf</FileTypesToDelete>
setting variable in script
[string[]]$FileTypesToDelete = @($configfile.Settings.FileTypesToDelete) #$FileTypesToDelete =$configfile.Settings.FileTypesToDelete
i've tried both the above ways to set the $FileTypesToDelete var and the code where I'm using this:
$logFiles = Get-Childitem $dir"\*" -Include $FileTypesToDelete,$liveSiteLogs -Exclude $configfile.Settings.FileExclusions | Where {$_.LastWriteTime -le "$LastWrite"}
when I run this logic i get this error:
Get-ChildItem : Cannot convert 'System.String[]' to the type 'System.String' required by parameter 'Include'. Specified method is not supported. At C:\Users\pmcma\Documents\Projects\Replace FileCleaner with PowerShell Script\TestSnippets.ps1:53 char:45+ $logFiles = Get-Childitem $dir"\*" -Include $FileTypesToDelete,$liveSiteLogs -Ex ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetChildItemCommand
but if I change this around and hard-code the values to be delete the code works fine:
$logFiles = Get-Childitem $dir"\*" -Include "*.txt","*.log",".mf", $liveSiteLogs -Exclude $fileExclusions | Where {$_.LastWriteTime -le "$LastWrite"}
but I want to read these values in from a config file so can anyone enlighten me as to why my top array is failing?
Thanks in advance