Tôi đã có một kịch bản PowerShell thực sự đơn giản (xem bên dưới). Tôi đã có installutil aliased bằng cách sử dụng sau đây trong hồ sơ cá nhân của tôi:C# Powershell snapin không đăng ký bằng cách sử dụng installutil
set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
Trong PowerShell tôi chỉ đơn giản:
installutil assemplylocation.dll
này trả về thành công. (Cài đặt/Cam kết cả hai đều thành công). Tuy nhiên, khi tôi kiểm tra sổ đăng ký, hoặc trong PowerShell sử dụng get-pssnapin -registered nó không hiển thị lắp ráp của tôi. Tôi đã làm điều này vào ngày khác và nó hoạt động tốt, nhưng tôi dường như không thể lặp lại nó ... xin vui lòng tư vấn cho.
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!");
}
}
}
Issue là với chạy này trong phiên bản 32bit của PowerShell, thay vì 64 bit ... – downatone