如何创建 cmdlet?

发布于 2024-07-11 08:24:44 字数 120 浏览 5 评论 0原文

我已经用 c# .net 编写了我的程序。 我想将其转换为 powershell cmdlet。 我被指示使用 pssnapin 和 getproc 程序。 任何人都可以帮我吗..

问候 阿伦

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

左秋 2024-07-18 08:24:44

要创建 PowerShell cmdlet,我建议您阅读 简单的 Windows PowerShell cmdlet 开发和调试,作者:Bart De Smet (B#),它是创建和调试 cmdlet 的一个很好的演练(按照它说的做!)

另外,我我发现专业 Windows PowerShell 编程,ISBN 978-0470173930,(ISBN-10) 0470173939 非常适合创建 cmdlet 和提供程序。

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.

生生不灭 2024-07-18 08:24:44

因此,这是您可以继承的 PSCmdlet-Class[来自 medata]。

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);
    }
}

为了加载 cmdlet,您需要另外对它们进行签名,因为 Powershell 不会执行未签名的代码。

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.

暮年 2024-07-18 08:24:44

安装Windows powershell模板,您将获得pssnapin程序,使用它您可以将.cs文件转换为dll。 然后在msdn中搜索getproc程序。 我记不太清楚了,但是会有一个方法首先被执行。 你在该方法中调用你的dll文件。 我不记得代码了,但这是要做的程序。

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.

司马昭之心 2024-07-18 08:24:44

看一下这篇文章:在 VB 2005 中创建 PowerShell Cmdlet。 它使用 VB 2005,但过程与 C# 相同。

完全公开,我写了这篇文章,但我不会因为你看它而得到报酬。 :)

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. :)

爱她像谁 2024-07-18 08:24:44

另请检查 http://blogs.msdn.com/daiken/。 特别是从 2007 年 2 月到 2007 年 6 月的所有月份。您将找到 Visual Studio 模板链接(对于 2005 年,也适用于 Express),以及几个示例/实验。

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.

你爱我像她 2024-07-18 08:24:44

PowerTime 项目 (http://code.google.com/p/powertime/)是开源的,它实现了许多 cmdlet。 非常适合让您入门的演示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文