首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法注册我的cmdlet

无法注册我的cmdlet
EN

Stack Overflow用户
提问于 2013-02-12 04:42:42
回答 1查看 167关注 0票数 0

基本上代码来自于msdn.microsoft.com

构建代码后,打开命令提示符并键入:InstallutilMycmdlets.dll%PATH%/ -i

结果表明,安装阶段已成功完成,提交阶段也已成功完成。然而,如果我去:

Get-PSSnapin -Registered,只显示sqlServerCmdletSnapin,但我的cmdlet不在那里。添加pssnapin也不起作用。

代码语言:javascript
复制
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.ComponentModel;

namespace Mycmdlets
{

[Cmdlet("hy", "Hello")]
public class GetHelloCommand : Cmdlet
{
    protected override void EndProcessing()
    {
        WriteObject("Hello", true);
    }
}

[RunInstaller(true)]
public class GetProcPSSnapIn01 : PSSnapIn
{
    /// <summary>
    /// Create an instance of the GetProcPSSnapIn01 class.
    /// </summary>
    public GetProcPSSnapIn01()
        : base()
    {
    }

    /// <summary>
    /// Specify the name of the PowerShell snap-in.
    /// </summary>
    public override string Name
    {
        get
        {
            return "GetProcPSSnapIn01";
        }
    }

    /// <summary>
    /// Specify the vendor for the PowerShell snap-in.
    /// </summary>
    public override string Vendor
    {
        get
        {
            return "Microsoft";
        }
    }

    /// <summary>
    /// Specify the localization resource information for the vendor. 
    /// Use the format: resourceBaseName,VendorName. 
    /// </summary>
    public override string VendorResource
    {
        get
        {
            return "GetProcPSSnapIn01,Microsoft";
        }
    }

    /// <summary>
    /// Specify a description of the PowerShell snap-in.
    /// </summary>
    public override string Description
    {
        get
        {
            return "This is a PowerShell snap-in that includes the get-proc cmdlet.";
        }
    }

    /// <summary>
    /// Specify the localization resource information for the description. 
    /// Use the format: resourceBaseName,Description. 
    /// </summary>
    public override string DescriptionResource
    {
        get
        {
            return "GetProcPSSnapIn01,This is a PowerShell snap-in that includes the get-proc cmdlet.";
        }
    }
}
}

编辑:

对于任何有兴趣了解解决方案的人来说,原因只是系统不支持x64。解决方案就在c#项目的属性中,将平台目标设置为“any CPU”,而不是x86或x64。

此外,Get-PSSnapin不会显示错误消息,但如果您从Visual Studio的命令提示符运行它,它将显示工作正常;但是,在powershell命令提示符上运行它将显示失败消息。

EN

回答 1

Stack Overflow用户

发布于 2013-12-12 00:11:34

根据Nacht的评论,我会将答案粘贴上去:

对于任何有兴趣了解解决方案的人来说,原因只是系统不支持x64。解决方案就在c#项目的属性中,将平台目标设置为“any CPU”,而不是x86或x64。

此外,Get-PSSnapin不会显示错误消息,但如果您从Visual Studio的命令提示符运行它,它将显示工作正常;但是,在powershell命令提示符上运行它将显示失败消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14820500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档