我想删除几个文件夹的内容。 我有什么:Powershell Select-Object如何获得值数组
$Config = @{
InstallPath = 'C:\Program Files\App'
SubPaths = @('www\app1', 'www\app2', 'www\app3')
}
这里是代码来获取内容:
$Config.SubPaths | Select-Object { Join-Path $Config.InstallPath $_ } | Get-ChildItem
但它不工作,因为Get-ChildItem
接收对象象下面这样:
@{ Join-Path $Config.InstallPath $_ =C:\Program Files\App\www\app1}
错误:
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
如何将Select-Object
的结果转换为简单的字符串数组?或者使代码更好的其他方法?
'$ Config.SubPaths | ForEach-Object {Join-Path $ Config.InstallPath $ _} | Get-ChildItem' – Matt