Reputation: 1973
I just feel really stupid right now. I forgot how to iterate over an array created by Select-Object
, and I can't find a solution.
I have a command like this:
$sitepublish = gci "W:\PublishSettings\$remoteIIS" | select FullName,BaseName
Which returns objects like this:
@{FullName=\\server\wdp$\PublishSettings\xy.PublishSettings; BaseName=xy}
How do I know iterate over it to get the FullName
and the BaseName
property for each object?
I tried this:
$sitepublish.Keys | % {
Write-Host $_.FullName -fore Blue
Write-Host $_.BaseName -fore Green
}
But it doesn't return anything.
Instead of .keys
I also tried .properties
, .psobject.properties
, .getenumerator()
and also just the variable without anything else (so just $sitepublish | % {}
).
Upvotes: 1
Views: 1411
Reputation: 58931
You can use the Foreach-Object
cmdlet:
$sitepublish | Foreach-Object {
Write-Host $_.FullName -fore Blue
Write-Host $_.BaseName -fore Green
}
Upvotes: 1