3

One of Azure cmdlets, namely New-AzureServiceProject, changes the current directory upon its completion (maybe a bug?).

For further lines in my script to work, I need to roll back this change, what's the best way to do it? Calling "cd", if I'm not wrong, would affect the current working dir if my scipt was called from some other directory. So maybe I should use Push-Location / Pop-Location somehow? Or is there a way to prevent 3rd party cmdlets from changing the current location?

4

1 回答 1

5

The usual way to handle this is to Push-Location before calling the cmdlet that changes dir and then call Pop-Location afterwards. AFAIK there is no way to prevent a cmdlet from changing the directory short of temporarily redefining cd or overriding Set-Location with a proxy function. Then again, the cmdlet may be using .NET methods to change the directory so even a proxy function may not be foolproof.

于 2012-09-18T13:54:19.097 回答