3

I'm writing a binary powershell module in C# and I can't seem to find out to get the current working directory from within a command.

My first thought was to do a simple Directory.GetCurrentDirectory(); from the System.IO library but it only seems to give me the directory that powershell was launched in.

How can I get the current directory within a binary powershell module during a command execution?

Thanks

jonfriesen
  • 625
  • 6
  • 19

1 Answers1

3

Assuming your cmdlet derives from PSCmdlet, using CurrentProviderLocation("FileSystem").ProviderPath should do the job nicely (untested).

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
  • In the event that I decide to derive from the base Cmdlet class, do you have any suggestions? I'm finding the PSCmdlet useful but a little bit restrictive. – jonfriesen Dec 17 '14 at 06:01
  • 1
    You might hack up something with multiple classes, or maybe just cheat and call `Convert-Path .`. Probably ask a new question about that. – Nathan Tuggy Dec 17 '14 at 06:08