简体   繁体   English

如何模块化powershell脚本

[英]how to modularize powershell scripts

I'm a programmer, though new to powershell. 我是程序员,虽然是PowerShell的新手。 I am scripting tasks/configurations such as these: 我正在编写如下脚本的任务/配置:

在此输入图像描述

  1. I would like to be able to run these with some type of "wrapper" that can manage errors, and handle execution flow 我希望能够使用某种类型的“包装器”来运行它们,这些“包装器”可以管理错误并处理执行流程
  2. I would be running these in both Azure and on-premises environments 我将在Azure和本地环境中运行它们
  3. We would like to have a good logging and diagnostics built in. 我们希望内置良好的日志记录和诊断功能。

How should small powershell scripts be wrapped in a way to make the solution modular and testable? 如何将小型PowerShell脚本包装成使解决方案模块化和可测试的方式?

For at least some of these tasks, it sounds like you would be better served by using a Configuration Management framework like PowerShell Desired State Configuration . 对于至少其中一些任务,听起来使用像PowerShell Desired State Configuration这样的配置管理框架会更好。

  1. Errors are handled or reported, state is ensured (attempted), execution happens on a schedule or manually. 处理或报告错误,确保(尝试)状态,按计划执行或手动执行。
  2. Runs in Azure or on-prem. 在Azure或本地运行。
  3. Logging and diagnostics are built-in and part of it. 记录和诊断是内置的,也是其中的一部分。

Of course other CM solutions like Puppet and Chef are available as well. 当然还有其他CM解决方案,如Puppet和Chef。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM