w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Accessing variables outside foreach inside it in powershell

Your foreach command should look like below. Notice that, you are missing a echo command for printing the line and you must separate both the different command using ;

foreach ( $item in $content ) {"Items under the folder
$path$item are :"; dir -path "$path$item" | select name,mode }

You can as well try this using ForEach-Object commandlet

dir -path $path | where { $_.Mode -match "^d.*" }|ForEach-Object
{Write-Host "Items under the folder $path$_ are :"; dir -path "$path$_" |
select name,mode}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.