我想刪除幾個文件夾的內容。 我有什麼: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