title: How to get the current directory of the cmdlet being executed
body: <p>This should be a simple task, but I have seen several attempts on how to get the path to the directory where the executed cmdlet is located with mixed success. For instance, when I execute <code>C:\temp\myscripts\mycmdlet.ps1</code> which has a settings file at <code>C:\temp\myscripts\settings.xml</code> I would like to be able to store <code>C:\temp\myscripts</code> in a variable within <code>mycmdlet.ps1</code>.</p>
  <p>This is one solution which works (although a bit cumbersome):</p>
  <pre><code>$invocation = (Get-Variable MyInvocation).Value
  $directorypath = Split-Path $invocation.MyCommand.Path
  $settingspath = $directorypath + '\settings.xml'
  </code></pre>
  <p>Another one suggested this solution which only works on our test environment:</p>
  <pre><code>$settingspath = '.\settings.xml'
  </code></pre>
  <p>I like the latter approach a lot and prefer it to having to parse the filepath as a parameter each time, but I can't get it to work on my development environment. What should I do? Does it have something to do with how PowerShell is configured?</p>