WMIC is finally coming to an end: How to migrate to PowerShell, a required course for system administrators

WBOY
Release: 2024-03-04 10:00:05
forward
1108 people have browsed it

WMIC 终将谢幕:如何迁移到 PowerShell,系统管理员的必修课

WMIC is an important tool for system administrators. It provides an efficient and precise way to manage Windows systems under the "Command Prompt". Administrators can use WMIC to perform system configuration, query and monitoring operations.

Microsoft has announced that WMIC will be phased out in future Windows versions:

  • Windows 10 21H1: The WMIC user interface (UI) is no longer recommended.
  • Windows 11 23H2 and 22H2: WMIC is provided as an "optional feature" but is still installed by default.
  • Windows 11 24H2: WMIC will be completely removed.

In addition, starting from January 29, 2024, WMIC is only provided as an optional feature in the Windows preview version and is no longer installed by default.

So, what should users who rely on WMIC do for their work? Microsoft recommends using Windows PowerShell instead of WMIC.

PowerShell is a command line interpreter and scripting environment based on the .NET Framework with more powerful features and more flexible syntax.

Next, let us first review the main functions of WMIC, and then introduce how to use PowerShell to replace these functions.

What is WMIC

WMIC stands for Windows Management Instrumentation Command-line, which is a command line tool. It provides access to Windows Management Instrumentation (WMI). WMI is a powerful management framework in Windows for data management and operations.

By using WMIC, administrators can easily perform various Windows management tasks. Combined with WMI scripts and applications, as well as WinRM (Windows Remote Management) and SCCM (System Center Configuration Manager), management tasks can be automated on remote computers. WMIC provides powerful functions to easily access and manage various information and functions of the Windows operating system through the command line or scripts. Administrators can use WMIC to query system information, install software, configure network settings, etc. At the same time, WMIC also supports remote management, and administrators can easily manage multiple computers through remote connections. By combining WMI scripts and applications, administrators can more flexibly customize management tasks and achieve automated execution. With the help of tools such as WinRM and SCCM, remote management can be carried out more efficiently, improving management efficiency and reducing manual operations

Tight integration with WMIC allows users to query and adjust system settings. For example, Windows screen brightness can be easily adjusted through WMIC. Use the following WMIC commands to get your computer's model, name, manufacturer, and system type.

wmic computersystem get manufacturer,model,name,systemtype
Copy after login

Use WMIC command to obtain computer information

This command can quickly provide key system information and is extremely useful for system administrators.

Why Microsoft decided to phase out WMIC

WMIC Deprecation Timetable

Since WMIC is so easy to use, why does Microsoft abandon it and promote PowerShell as a replacement? This decision is mainly based on the following reasons:

  1. Technology Development: PowerShell provides a more modern and powerful way to access and manage WMI, as well as many other system management functions. It supports more complex scripts, more flexible commands, and a broader feature set, making it the first choice for system administration tasks.
  2. Performance improvement: Compared with WMIC, PowerShell usually performs better in terms of performance and efficiency. Especially when processing large amounts of data or performing complex management tasks, PowerShell cmdlets run more efficiently.
  3. Security considerations: WMIC may be used by malware or attackers to execute remote commands or deploy malicious code. PowerShell effectively reduces this type of risk by implementing powerful security features such as policy control and more detailed permission management.
  4. Unified standards: Centralizing the use of PowerShell to manage system tasks helps to unify and standardize the tool set, simplify system management work, improve efficiency, and reduce the need for administrators to switch between different tools.
  5. Community support: PowerShell has an active community that provides a wealth of resources, scripts, and modules. Continuous investment by Microsoft and the community ensures that PowerShell is constantly updated and improved, while the development of WMIC has been relatively stagnant.

Although WMIC was a very useful management tool in the past, as technology evolves and new tools emerge, Microsoft believes that a move to more modern, more secure, and more powerful management tools is necessary.

This reflects an industry norm: As technology advances, old tools will be replaced by new, more advanced tools to meet the needs of modern IT environments.

Use PowerShell, WMI and CIM instead of WMIC

Before we formally explore alternatives, we need to clarify several core concepts:

  • Windows 系统内置了 WMI 和 CIM 的 cmdlets,为管理员提供了强大的管理工具。
  • WMI(Windows 管理接口)基于 CIM(通用信息模型)标准,主要用于获取和展示计算机信息。CIM 是行业通用标准,虽然它本身不直接支持远程数据访问,但 WMI 利用了 DCOM(分布式组件对象模型)和 RPC(远程过程调用)等技术,实现了在网络连接的远程系统上使用 CIM。不过,WMI 在通过防火墙进行远程设备查询时存在一定局限性。
  • PowerShell 中的 WMI 和 CIM cmdlets 是向着更安全、更高效、兼容性更强的管理工具转型的重要一步。接下来,我们将通过一些基本实例,帮助你完成这一转型过程。

CIM cmdlets 使用示例

CIM cmdlets 通过 WS-Management 协议实现数据交换,该协议比 DCOM 更适合远程管理,尤其是在需要穿透防火墙时。

  • 获取系统信息
Get-CimInstance -ClassName CIM_ComputerSystem
Copy after login

该命令会显示当前计算机的系统信息,输出内容与 WMIC 命令相似。

使用 Get-CimInstance 获取系统信息

  • 获取启动配置
Get-CimInstance -ClassName CIM_OperatingSystem
Copy after login

该命令提供了操作系统的详细信息,包括系统目录、构建号和版本信息等。

WMI cmdlets 使用示例

虽然比较推荐使用 CIM cmdlets,但 PowerShell 同样支持直接使用 WMI 的 cmdlets。例如:

  • 获取进程列表
Get-WmiObject -Class Win32_Process
Copy after login

该命令会列出当前运行的所有进程。

使用 Get-WmiObject 查看进程列表

  • 获取服务状态
Get-WmiObject -Class Win32_Service | Where-Object {$_.State -eq "Running"}
Copy after login

该命令会筛选出所有当前正在运行的服务。

使用 Get-WmiObject 查看运行的服务

WMIC 脚本向 PowerShell 转换

如果你之前主要使用 WMIC 进行管理任务,现在可以考虑将这些脚本转换为 PowerShell cmdlets。

PowerShell 提供了更多命令选项和更灵活的脚本功能,在多数情况下,这个转换过程直接且简单。

转换过程中,Get-CommandGet-Help cmdlets 能帮助你快速找到对应的 PowerShell 命令,及其使用方法。

例如,要查找所有与实例相关的可用 CIM 命令,可以使用:

Get-Command -Noun CimInstance*
Copy after login

使用 Get-Help 获取帮助

同时,Get-Help命令能提供特定 cmdlet 的详细使用说明和示例,这对学习新命令非常有帮助:

Get-Help Get-CimInstance -Full
Copy after login

通过这种方式,你就可以逐步替换 WMIC 命令,从而提高系统管理的效率和安全性。

要深入了解 PowerShell 中的 WMI 和 CIM 命令使用方法,可以参考微软发布的这篇指南。

自 2016 年起,微软就已经开始逐步淘汰 WMIC。虽然没有宣布具体的弃用日期,但想必已经迫在眉睫。因此,建议系统管理员尽快开始探索迁移解决方案,把 PowerShell 的 WMI 和 CIM 工具融入日常管理工作和编程任务中。

The above is the detailed content of WMIC is finally coming to an end: How to migrate to PowerShell, a required course for system administrators. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!