title: How do I deal with Paths when writing a PowerShell Cmdlet?
body: <p>What is the proper way to receive a file as a parameter when writing a C# cmdlet?  So far I just have a property LiteralPath (aligning with their parameter naming convention) that is a string. This is a problem because you just get whatever is typed into the console; which could be the full path or could be a relative path.</p>
  
  <p>Using Path.GetFullPath(string) doesn't work. It thinks I'm currently at ~, I'm not.  Same problem occurs if I change the property from a string to a FileInfo.</p>
  
  <p>EDIT: For anyone interested, this workaround is working for me:</p>
  
  <pre><code>    SessionState ss = new SessionState();
      Directory.SetCurrentDirectory(ss.Path.CurrentFileSystemLocation.Path);
  
      LiteralPath = Path.GetFullPath(LiteralPath);
  </code></pre>
  
  <p>LiteralPath is the string parameter.  I'm still interested in learning what is the recommended way to handle file paths that are passed as parameters.</p>
  
  <p>EDIT2: This is better, so that you don't mess with the users current directory, you should set it back.</p>
  
  <pre><code>            string current = Directory.GetCurrentDirectory();
              Directory.SetCurrentDirectory(ss.Path.CurrentFileSystemLocation.Path);
              LiteralPath = Path.GetFullPath(LiteralPath);
              Directory.SetCurrentDirectory(current);
  </code></pre>