目前,我正在尝试创建我的第一个PowerShell管理单元。我遵循了本教程:如何创建PowerShell管理单元和一切正常工作,直到我试图调用我的定制cmdlet。此外,我还添加了一个"Post事件“来注册程序集。
"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中的所有操作。平台设置为"Active (任意CPU)“。
这是我的cmdlet代码:
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时遇到的错误:
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我做错了什么,关于目标平台(x86)有什么设置错误吗?
发布于 2014-01-05 20:54:59
如果选择x86作为平台,还需要确保使用的是x86版本的PowerShell。关于如何做到这一点,请参见这里。您可能正在使用x64版本的powershell,这是默认的。请参阅这里更多信息。
或者将目标更改为AnyCPU,并使用installutil注册管理单元两次。一次使用32位版本,也使用64位版本(C:\Windows\Microsoft.NET\Framework64\v2.0.50727\installutil.exe).
发布于 2021-11-09 08:40:43
如果您正在制作像atom这样的IDE
你应该从PowerShell打开原子,就像
只需输入 atom
Should work发布于 2021-11-09 08:52:54
如果您正在制作像atom这样的IDE
你应该从PowerShell打开原子,就像
只需输入 atom
Should workhttps://stackoverflow.com/questions/20938389
复制相似问题