Je suis en train de supprimer le contenu de quelques dossiers. Ce que j'ai:Powershell Select-Object comment obtenir tableau de valeurs
$Config = @{
InstallPath = 'C:\Program Files\App'
SubPaths = @('www\app1', 'www\app2', 'www\app3')
}
Et voici le code pour obtenir le contenu:
$Config.SubPaths | Select-Object { Join-Path $Config.InstallPath $_ } | Get-ChildItem
Mais ça ne marche pas, parce que Get-ChildItem
objet comme ci-dessous reçoit:
@{ Join-Path $Config.InstallPath $_ =C:\Program Files\App\www\app1}
erreur :
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
Comment puis-je convertir résultat de Select-Object
à simple tableau de chaînes? Ou toute autre approche pour améliorer le code?
'$ Config.SubPaths | ForEach-Object {Join-Path $ Config.InstallPath $ _} | Get-ChildItem' – Matt