View Single Post
Old 08-29-2007   #9 (permalink)
Kiron


 
 

Re: get-child item question from a newbie

Extending Keith's solution to change dir to each subDir, execute multiple
scripts from there and change dir back to the parent afterwards in each
loop.

$scriptsPath = "C:\Scripts"
# scripts to execute
$scripts = 'myScript1', 'myScript2', 'myScript3'
# filter first level subDirs
get-item * | where {$_.PSIsContainer} |
# push the current location to the default stack and cd to the next subDir
foreach {push-location $($_.fullName)
# send the script names down the pipe
$scripts |
# use the call operator to execute each script
foreach {& "$scriptPath\$_"}
# pop the parent's location from the stack and cd back to it
pop-location
}

--
Kiron

My System SpecsSystem Spec