我有一个非常简单的 powershell 脚本(见下文)。我在我的个人资料中使用以下内容获得了 installutil 别名:
set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
在powershell中,我只是:
installutil assemplylocation.dll
这成功返回。(安装/提交都成功完成)。然而,当我检查注册表或在 powershell 中使用 get-pssnapin -registered 时,它不会显示我的程序集。前几天我做了这个,效果很好,但我似乎无法复制它......请指教。
using System;
using System.Management.Automation;
using System.ComponentModel;
namespace PSBook_2_1
{
[RunInstaller(true)]
public class PSBookChapter2MySnapIn : PSSnapIn
{
public PSBookChapter2MySnapIn()
: base()
{ }
// Name for the PowerShell snap-in.
public override string Name
{
get
{
return "Wiley.PSProfessional.Chapter2";
}
}
// Vendor information for the PowerShell snap-in.
public override string Vendor
{
get
{
return "Wiley";
}
}
// Description of the PowerShell snap-in
public override string Description
{
get
{
return "This is a sample PowerShell snap-in";
}
}
}
// Code to implement cmdlet Write-Hi
[Cmdlet(VerbsCommunications.Write, "Hi")]
public class SayHi : Cmdlet
{
protected override void ProcessRecord()
{
WriteObject("Hi, World!");
}
}
// Code to implement cmdlet Write-Hello
[Cmdlet(VerbsCommunications.Write, "Hello")]
public class SayHello : Cmdlet
{
protected override void ProcessRecord()
{
WriteObject("Hello, World!");
}
}
}