为什么我会选择 Powershell 而不是 WMI 来开发管理界面?

发布于 2024-07-08 11:22:06 字数 264 浏览 7 评论 0原文

我们正在讨论为我们的分布式系统开发改进的管理基础设施。 我们使用 COM、Web 服务和 .NET 组件。 由于我们基于 Microsoft Windows Server XP/2003,我想我们基本上有两个选择:

  1. Powershell cmdlet
  2. 使用 System.Management 的 WMI 类和本机代码的 WMI 提供程序(类、实例、方法、事件)

为什么我们选择 Powershell 而不是 WMI?

We are discussing development of an improved management infrastructure for our distributed system.
We use COM, web services and .NET components. Since we're based on Microsoft Windows Server XP/2003, I guess, we basically have two options:

  1. Powershell cmdlets
  2. WMI classes using System.Management and WMI providers for native code (class, instance, method, event)

Why would we choose Powershell over WMI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

稀香 2024-07-15 11:22:06

我会选择 PowerShell 而不是 WMI,原因如下:

  1. 编写 cmdlet 只是添加 .NET 类。
  2. PowerShell 运行时提供内置的命令行解析。
  3. 在 PowerShell 中编写管理界面使管理员能够将应用程序的管理与其他应用程序和服务(例如 Exchange、Active Directory 或 SQL Server)的管理集成起来。
  4. PowerShell 环境使管理员可以使用管道,从而能够更高效地完成应用程序的管理任务。
  5. 可发现性。 PowerShell 通过 Get-Command、Get-Member 和 Get-Help 为管理员提供了一个非常易于发现的工作环境,从而缩短了维护应用程序的学习曲线。

即使您采用 WMI 路线,PowerShell 也确实支持使用 WMI(尽管存在一些故障)。

对我来说,PowerShell 是向应用程序提供面向任务界面的最佳方式。 凭借 Microsoft 一直提供的 PowerShell 支持,它现在和将来都是管理整个企业应用程序和服务的一致界面。

我的日常工作是管理员,我正在推动所有与我合作的供应商提供 PowerShell 管理 API,因为这使得管理应用程序的学习曲线和上下文切换要低得多。 在开发方面,我已经为我使用的一个开源产品编写了(并且仍在研究)一系列 PowerShell cmdlet,并且正在为单独的应用程序编写另一组 cmdlet。

I would choose PowerShell over WMI for the following reasons:

  1. Writing a cmdlet is only adding a .NET Class.
  2. The PowerShell runtime provides command line parsing built in.
  3. Writing your management interface in PowerShell allows administrators the ability to integrate management of your application with that of other applications and services (like Exchange, Active Directory, or SQL Server).
  4. The PowerShell environment makes the pipeline available to administrators, enabling management tasks for your application to be done more efficiently.
  5. Discoverability. PowerShell, via Get-Command, Get-Member, and Get-Help, provides an extremely discoverable environment for admins to work in, resulting in a shorter learning curve to maintaining your application.

Even if you go the WMI route, PowerShell does have support for working with WMI (though there are a few glitches).

To me, PowerShell is the best way to surface a task oriented interface to an application. With the support Microsoft has been providing PowerShell, it is and will be a consistent interface to managing applications and services throughout the enterprise.

My day job is as an admin and I'm pushing all the vendors I work with towards surfacing a PowerShell management API, as this makes the learning curve and context switching for managing applications much lower. On the development side, I have written (and am still working on) a series of PowerShell cmdlets for one open source product I work with and am working on another set for a separate application.

冷清清 2024-07-15 11:22:06

Jeffrey Snover 回答了“为什么使用 PowerShell”此处。 这篇文章是在 SQL 的背景下进行的,但在这里非常适用。

Jeffrey Snover answers the "why PowerShell" here. The post is in the context of SQL, but very much applicable here.

岁月苍老的讽刺 2024-07-15 11:22:06

我不确定我是否会做出决定。 这并不完全是非此即彼……你可以选择两者都做。

WMI 可以被许多不同的东西使用,而不仅仅是 PowerShell。 为什么不在 PowerShell 中编写管理工具,然后将该 WMI 包装在一些面向任务的 cmdlet 中,以使管理员的工作变得更轻松? 这就是一些 MS 产品团队选择做的事情,特别是当他们有其他 WMI 消费者想要继续支持时。

如果您已经有了合适的 .NET 代码,将其转换为 cmdlet 可能比将其转换为 WMI 提供程序更快。 如果是这种情况,并且速度是一个问题,那就选择更容易的方法。 但无论您做什么,您始终可以将其包装在管理员的 PowerShell cmdlet 中,这绝对是推荐的方法。

I'm not sure I'd make the decision. It's not exactly either-or... you can choose to do both.

WMI can be consumed by a number of different things, not just PowerShell. Why not write your management instrumentation in PowerShell, and then wrap that WMI in some task-oriented cmdlets to make things easier on administrators? That's what some MS product teams are choosing to do, especially when they have other consumers of WMI they want to continue supporting.

If you've already got suitable .NET code, turning that into a cmdlet may be faster than turning it into a WMI provider. If that's the case, and speed is a concern, go with what's easier. But no matter what you do, you can always wrap it in a PowerShell cmdlet for admins, which is definitely the recommended approach.

流年里的时光 2024-07-15 11:22:06

不确定您目前提供的信息是否可以回答这个问题。 我的直觉是你应该使用 powershell,因为听起来你可能已经有了一些 .Net 代码。 但这确实取决于您想要做什么。

Not sure that this can be answered with the information that you have provided so far. My gut feeling would be that you should use powershell since it sounds like you may already have some .Net code. But it really does just depend on exactly what you are trying to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文