How can I create PSProvider specific parameters for cmdlets?

34 views
Skip to first unread message

Sung M Kim

unread,
Oct 8, 2006, 6:22:49 PM10/8/06
to
I was creating a PsProvider extending ContainerCmdletProvider.

While overriding methods, I came across, "NewItem" function that I had
to override(with the following C# method signature):
----------------------------------------
protected override void NewItem(string path, string itemTypeName,
object newItemValue)
----------------------------------------

Now, what I would like to accomplish is, I would like to have
"New-Item" to have more parameters inside the PsProvider I am writing.

How can I specify addiation provider-specific parameters?

For ex) within "Certificate" PsProvider, "Get-ChildItem" has
"-CodeSigningCert" parameter. I am wondering how it can be done.

By the way, "NewItem" is just one of the functions I would like to add
more parameters to.

Thank you in advance.

Narayanan Lakshmanan [MSFT]

unread,
Oct 9, 2006, 2:00:49 PM10/9/06
to
You can override the following function to enable it to take additional
parameters

protected override object NewItemDynamicParameters(string path,
string type, object newItemValue)

Refer to the PowerShell Managed Reference in the Windows SDK for
documentation on the same

--
Narayanan Lakshmanan [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Sung M Kim" <DontBother...@gmail.com> wrote in message
news:1160346169.2...@h48g2000cwc.googlegroups.com...

Sung M Kim

unread,
Oct 9, 2006, 7:35:04 PM10/9/06
to
Ah great. Thank you for the direction to take ;)

Sung M Kim

unread,
Oct 9, 2006, 10:34:10 PM10/9/06
to
Ok, Now I am faced with a new problem but still related to the main
subject.
I have now created a new dynamic parameter for "Get-Item" cmdlet in
"GetItemDynamicParameters" and added "EventID" parameter to "Get-Item".

protected override object GetItemDynamicParameters(string path)
{
WriteVerbose("GetItemDynamicParameters:path = " + path);

RuntimeDefinedParameterDictionary dic =
new RuntimeDefinedParameterDictionary();

ParameterAttribute attrib = new ParameterAttribute();
attrib.ParameterSetName = "Path";
attrib.Mandatory = false;
attrib.ValueFromPipeline = true;
Collection<Attribute> col =
new Collection<Attribute>();
col.Add(attrib);

RuntimeDefinedParameter eventIdParam =
new RuntimeDefinedParameter("EventID", typeof(int) ,
col);
dic.Add("EventID", eventIdParam);

return dic;
}

Now the problem is that, I am not sure how I can access the argument
passed to "EventID" parameter inside overriden "GetItem" method. Is
there a utility method that can be used to access the argument for the
dynamic parameter?

Lee Holmes [MSFT]

unread,
Oct 11, 2006, 12:37:31 PM10/11/06
to
Those are available through the DynamicParameters property.

Lee

"Sung M Kim" <DontBother...@gmail.com> wrote in message

news:1160447650.7...@m73g2000cwd.googlegroups.com...

Sung M Kim

unread,
Oct 11, 2006, 6:59:22 PM10/11/06
to

Lee Holmes [MSFT] wrote:
> Those are available through the DynamicParameters property.
>
> Lee

Not being able to navigate around(using tree views on MSDN) PowerShell
classes made it a bit harder for me to browse around...


Thank you for the tips there Lee.

By the way, when will System.Management.Automation.* classes for
PowerShell be available on MSDN?

Lee Holmes [MSFT]

unread,
Oct 12, 2006, 11:30:24 AM10/12/06
to
I'm not sure when they'll make it to msdn.microsoft.com (as opposed to
windowssdk.msdn.microsoft.com,) but they are already available online:
http://windowssdk.msdn.microsoft.com/en-us/library/system.management.automation.provider.aspx

(We of course continue to add and improve them, but they exist.)

--
Lee Holmes [MSFT]


Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Sung M Kim" <DontBother...@gmail.com> wrote in message
news:1160607562.8...@e3g2000cwe.googlegroups.com...

Reply all
Reply to author
Forward
0 new messages