何时选择通过PowerShell脚本开发PowerShell模块

我将为 Windows管理员编写一个PowerShell脚本,以帮助他们处理与Web应用程序部署相关的某些任务.

有什么理由我应该赞成或排除PowerShell模块(.psm1)的开发,而不是做一个PowerShell脚本(.ps1)?

开发脚本的论据

>简单性:我使用脚本的东西对于Windows管理员来说有点简单和直接,因为它不需要安装模块(但是我可能错了,因为我不是Windows Admin!).
>更快的开发:开发一个模块需要更仔细的编程内部方法的曝光,就像设计API一样,因此必须更加严格.

开发模块的参数:

>可重用性:这是首先要注意的事情:如果管理员想将脚本集成在自己的脚本中,他可能会更容易地重复使用暴露一个(或多个)cmdlet的模块,而不是调用我们的脚本?
> …

如果您知道PS脚本与PS模块的常见用例,或每种选择的技术限制,可能有所帮助.

要了解什么模块可以为您做,请阅读: http://msdn.microsoft.com/en-us/library/dd878310(v=vs.85).aspx

简而言之,

Windows PowerShell modules allow you to partition,organize,and abstract your Windows PowerShell code into self-contained,reusable units. With these reusable units,administrators,script developers,and cmdlet developers can easily share their modules directly with others. Script developers can also repackage third-party modules to create custom script-based applications. Modules,similar to modules in other scripting languages such as Perl and Python,enable production-ready scripting solutions that use reusable,redistributable components,with the added benefit of enabling you to repackage and abstract multiple components to create custom solutions.

如果您的脚本已经具有功能,并且不仅仅是为了执行单个任务而编写,您可以将其重命名为.PSM1以将其转换为模块.如果你不使用功能,当然别无选择,只能去.ps1.在这种情况下,每个.ps1将用于执行单个任务.当我和他人共享我写的脚本时,我总是喜欢模块.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...