현재 첫 번째 PowerShell 스냅인을 만들려고합니다. 이 자습서는 How to create a PowerShell Snapin을 따르고 사용자 정의 cmdlet을 호출 할 때까지 모든 것이 제대로 작동합니다. 또한 "게시 빌드 이벤트"를 추가하여 어셈블리를 등록했습니다. PowerShell 스냅인 Cmdlet CommandNotFoundException
"C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe" $(TargetPath)
는 그 후 나는 스냅인을 추가하고 그것이 마치 마법처럼 일 :
Add-PSSnapin CustomSrv.Commands
System.Automation 참조의 어셈블리 경로 :
C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll
내 대상 플랫폼으로 내가 선택 x86 및 x86 PowerShell에서도 모든 것을 실행하고 있습니다.
PS C:\WINDOWS\system32> Connect-CustomSrv
Connect-CustomSrv: The term 'Connect-CustomSrv' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Connect-CustomSrv
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-CustomSrv:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
:
namespace CustomSrv.Commands
{
[Cmdlet(VerbsCommunications.Connect, "CustomSrv")]
public class TestCmdlet1 : Cmdlet
{
protected override void BeginProcessing()
{
WriteObject("BeginProcessing() method - Execution has begun");
}
protected override void ProcessRecord()
{
WriteObject("ProcessRecord() method - Executing the main code");
}
protected override void EndProcessing()
{
WriteObject("EndProcessing() method - Finalizing the execution");
}
}
}
이 내가 cmdlet를 호출려고 할 때 내가지고있어 오류는 다음과 같습니다 플랫폼
이 내 cmdlet를 코드입니다 "활성 (모든 CPU)"로 설정
내가 잘못하고있는 부분은 타겟팅 플랫폼 (x86)과 관련하여 잘못된 설정이 있습니까?
스냅인은 더 이상 사용되지 않으며 (v2 이후) 유의해야합니다. 모듈을 대신 만들어야합니다. 그리고 네, 바이너리 모듈을 만들 수 있습니다. (http://csharpening.net/?p=738) – alroc
사용중인 PowerShell 버전은 무엇입니까? $ PSVersionTable을 수행하여 확인하십시오. 그리고 귀하의 어셈블리에 사용하고있는 .Net 버전은 무엇입니까? 그리고 alroc이 말하는 것처럼. 스냅은 더 이상 사용되지 않으며 모듈을 조회합니다. PowerShell 모듈을 순수하게 사용하여 Visual Studio가 필요하지 않거나 대상을 신경 쓰지 않아도됩니다. –
스냅인만을 지원하는 스냅인과 함께 스냅인을 사용하려는 경우, 안타깝게도 모듈로 전환하는 것은 나를위한 옵션이 아닙니다 ... .NET 버전 3.5 및 PowerShell 버전 4를 사용하고 있습니다. –