I am trying to delete contents of few folders. What I have:
$Config = @{
InstallPath = 'C:\Program Files\App'
SubPaths = @('www\app1', 'www\app2', 'www\app3')
}
And here is the code to get contents:
$Config.SubPaths | Select-Object { Join-Path $Config.InstallPath $_ } | Get-ChildItem
But it doesn't work, because Get-ChildItem receives object like below:
@{ Join-Path $Config.InstallPath $_ =C:\Program Files\App\www\app1}
Error:
Get-ChildItem : Cannot find drive. A drive with the name '@{ Join-Path $Config.InstallPath $_ =C' does not exist.
At line:1 char:85
+ ... elect-Object { Join-Path $Config.InstallPath $_ } | Get-ChildItem
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (@{ Join-Path $C...stallPath $_ =D:String) [Get-ChildItem], DriveNotFoun
dException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
How can I convert result of Select-Object to simple array of strings? Or any other approach to make code better?
$Config.SubPaths | ForEach-Object { Join-Path $Config.InstallPath $_ } | Get-ChildItem