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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
You might hack up something with multiple classes, or maybe just cheat and call Convert-Path .. Probably ask a new question about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.