I have written my program in c# .net. I want to convert it in to a powershell cmdlet. I was instructed to use pssnapin and getproc programs. Can anyone plz help me out..
Regards Arun
I have written my program in c# .net. I want to convert it in to a powershell cmdlet. I was instructed to use pssnapin and getproc programs. Can anyone plz help me out..
Regards Arun
Install windows powershell template thereby u will get the pssnapin program, using that you can convert your .cs file into a dll. Then search for getproc program in msdn. I don't remember exactly but there will be a method which will be executed at the first. you call your dll file in that method. I don't remeber the code, but this is the procedure to do.
So, here's the PSCmdlet-Class[from medata], that you can inherit from.
namespace System.Management.Automation
{
public abstract class PSCmdlet : Cmdlet
{
protected PSCmdlet();
public PSHost Host { get; }
public CommandInvocationIntrinsics InvokeCommand { get; }
public ProviderIntrinsics InvokeProvider { get; }
public InvocationInfo MyInvocation { get; }
public string ParameterSetName { get; }
public SessionState SessionState { get; }
public PathInfo CurrentProviderLocation(string providerId);
public Collection<string> GetResolvedProviderPathFromPSPath(string path, out ProviderInfo provider);
public string GetUnresolvedProviderPathFromPSPath(string path);
public object GetVariableValue(string name);
public object GetVariableValue(string name, object defaultValue);
}
}
In order to get your cmdlets loaded, you need to sign them additionally, because Powershell does not execute not signed code.
Take a look at this article, Creating PowerShell Cmdlets in VB 2005. It uses VB 2005, but the process is the same for C#.
Full disclosure, I wrote the article, but I do not get paid by you looking at it. :)
Check also http://blogs.msdn.com/daiken/. In particular all the months from February 2007 to June 2007. You'll find the Visual Studio template link (for 2005, also works in Express), and several examples/labs.
The PowerTime project (http://code.google.com/p/powertime/) is open source and it implements a number of cmdlets. Good for a demo to get you going.
To create a PowerShell cmdlet I would recommend you read Easy Windows PowerShell cmdlet development and debugging by Bart De Smet (B#) it's a great walk through for creating and debugging cmdlet's (Does what it says on the tin!)
Also I've found Professional Windows PowerShell Programming, ISBN 978-0470173930, (ISBN-10) 0470173939 very good for creating cmdlets and providers.