title: Run command in each sub directory using PowerShell
body: <p>I want to run <code>mvn clean compile</code> in each directory in my Eclipse workspace containing a <code>pom.xml</code> file.</p>
  
  <p>I was able to run <code>svn update</code> for each directory containing <code>.svn</code> like this:</p>
  
  <pre><code>PS C:\workspace&gt; Get-ChildItem -recurse -force | 
  where {$_.name -eq ".svn"} | 
  foreach {svn update $_.parent.FullName}
  </code></pre>
  
  <p>However, this gives the full path to <code>svn</code> and runs from the current directory. The <code>mvn clean compile</code> needs to be run inside the directory, afaik. Tried doing the following, but then I just get an error saying something can't be null. Seems to be the first <code>cd</code> call it complains about. Do I just have some syntax wrong, or am I using <code>foreach</code> wrong?</p>
  
  <pre><code>PS C:\workspace&gt; Get-ChildItem -recurse | 
  where {$_.name -eq "pom.xml"} | 
  foreach { cd $_.parent.name; mvn clean compile; cd ..; }
  </code></pre>