首先编写程序自定义功能
该程序引用了一个System.Management.Automation.dll,该dll在C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35文件夹下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
namespace PSBook.Chapter2
{
[Cmdlet(VerbsCommunications.Write, "Hello")]
public class SayHello : Cmdlet
{
protected override void ProcessRecord()
{
WriteObject("Hello,world");
}
}
[Cmdlet(VerbsCommunications.Write,"Hi")]
public class SayHi : Cmdlet
{
protected overr

本文档介绍了如何创建自定义PowerShell模块,包括编写Cmdlet功能,如Write-Hello和Write-Hi,并通过PSSnapIn定义模块基本信息。接着,详细阐述了生成DLL文件、在PowerShell中安装和注册模块的步骤。为了解决每次启动PowerShell需要手动添加模块的问题,文章建议将Add-PSSnapin命令写入profile.ps1文件,使得模块在启动时能自动加载。
最低0.47元/天 解锁文章
1143

被折叠的 条评论
为什么被折叠?



