开发者

PowerShell InitializeDefaultDrive

In my custom powershell provider I want the user to be able to skip the internal call to InitializeDefaultDrives.

The InitializeDefaultDrives method is called when the provider starts. I guess this is when I use the Add-SnapIn cmdlet to load my provider. So it looks like i'm searching for a way to add dynamic parameters to to the Add-SnapIn cmdlet.

I know i can just skip the implementation of InitializeDefaultDrives and have the user use new-PsDrive to add the drive manua开发者_开发知识库lly if desired. That is not want I want. I want to always create a default drive except in the case where the user wants to skip this.

Thanks!


AFAIK dynamic parameters only work when you control the source code i.e. in your code you can choose to expose a dynamic parameter based on the value of another parameter (like a path). Then your code does something different based on the value of the dynamic parameter. However, you should be able to accomplish what you want via a session preference variable.

$SuppressDriveInit = $true
Add-PSSnapin Acme

If the variable is not definied or is set to false, then go ahead and initialize the drive. It is low tech but should work fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜