何时选择通过PowerShell脚本开发PowerShell模块 [英] When to choose development of a PowerShell Module over PowerShell Script

查看:88
本文介绍了何时选择通过PowerShell脚本开发PowerShell模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我是否应该支持或排除开发 PowerShell模块(.psm1)而不是执行 PowerShell脚本(.ps1) ? >

开发脚本的参数

  • 简单性:我认为对于Windows管理员来说,使用脚本会更容易,更直接,因为它不需要安装模块(但是我可能不是很正确,因为我不是Windows管理员!).
  • 更快的开发:开发模块需要更仔细的编程以了解内部方法.就像设计API一样,因此必须更加严格.

开发模块的参数:

  • 可重用性:这是我想到的第一件事:如果管理员想将我们的脚本集成到自己的脚本中,那么他可能更容易重用暴露一个(或多个)模块的模块. )cmdlet而不是调用我们的脚本?
  • ...

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

解决方案

要了解哪些模块可以为您提供帮助,请阅读以下内容: 解决方案

To understand what modules can do for you, read this: http://msdn.microsoft.com/en-us/library/dd878310(v=vs.85).aspx

In a nut shell,

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.

If your script already has functions and is not just written to perform a single task, you can just rename it to .PSM1 to convert it to module. If you are not using functions, of course, there is no choice but to go for .ps1. In such a case, each .ps1 will be used to perform a single task. I always prefer modules when sharing the scripts I write with others.

这篇关于何时选择通过PowerShell脚本开发PowerShell模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆