C# 无法注册我的cmdlet

C# 无法注册我的cmdlet,c#,powershell,cmdlets,cmdlet,C#,Powershell,Cmdlets,Cmdlet,基本上,代码来自msdn.microsoft.com 生成代码后,打开命令提示符并键入:Installutil-I%path%/mycmdlet.dll 结果表明安装阶段成功完成,提交阶段也成功完成。然而,如果我去: 注册PSSnapin,只显示sqlServerCmdletSnapin,但我的cmdlet不在其中。添加pssnapin也不起作用 using System; using System.Management.Automation; using System.Management.A

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

生成代码后,打开命令提示符并键入:Installutil-I%path%/mycmdlet.dll

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

注册PSSnapin,只显示sqlServerCmdletSnapin,但我的cmdlet不在其中。添加pssnapin也不起作用

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.";
        }
    }
}
}
使用系统;
使用系统、管理、自动化;
使用System.Management.Automation.Runspaces;
使用系统组件模型;
命名空间mycmdlet
{
[Cmdlet(“hy”,“Hello”)]
公共类GetHelloCommand:Cmdlet
{
受保护的覆盖无效EndProcessing()
{
WriteObject(“Hello”,true);
}
}
[运行安装程序(true)]
公共类GetProcPSSnapIn01:PSSnapIn
{
/// 
///创建GetProcPSSnapIn01类的实例。
/// 
公共GetProcPSSnapIn01()
:base()
{
}
/// 
///指定PowerShell管理单元的名称。
/// 
公共重写字符串名
{
得到
{
返回“GetProcPSSnapIn01”;
}
}
/// 
///指定PowerShell管理单元的供应商。
/// 
公共重写字符串供应商
{
得到
{
返回“微软”;
}
}
/// 
///指定供应商的本地化资源信息。
///使用以下格式:resourceBaseName、VendorName。
/// 
公共重写字符串VendorResource
{
得到
{
返回“GetProcPSSnapIn01,Microsoft”;
}
}
/// 
///指定PowerShell管理单元的说明。
/// 
公共重写字符串描述
{
得到
{
return“这是一个包含get-proc cmdlet的PowerShell管理单元。”;
}
}
/// 
///指定描述的本地化资源信息。
///使用以下格式:resourceBaseName,Description。
/// 
公共重写字符串描述资源
{
得到
{
return“GetProcPSSnapIn01,这是一个包含get-proc cmdlet的PowerShell管理单元。”;
}
}
}
}
编辑: 对于任何有兴趣了解解决方案的人来说,原因只是系统不支持x64。解决方案只是在c#项目的属性中,将平台目标设置为“任意CPU”,而不是x86或x64


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

根据Nacht注释,我将答案粘贴到:

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


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

只是好奇,您有PS2.0吗?如果是这样,您应该研究二进制模块。它们更易于使用。@Graimer mine是3.0,但我不确定二进制模块是什么。。请检查并重试。我认为它们与管理单元之间没有太大区别,但它们不需要安装/注册。:-)如果您将模块文件夹放在
$env:PSModulePath
@Graimer中指定的位置之一,您可以像导入模块mymodule一样导入它们谢谢您的提示!我已经找到了我的问题的答案,但是你的评论仍然很感谢!作为将来的参考,如果您有自己问题的答案,您可以使用实际答案来回答,而不是对您的问题进行编辑-这样,从问题列表中查看问题的人就可以看到问题已经得到了回答,而无需单击它