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:
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.
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
Use WMIC command to obtain computer information
This command can quickly provide key system information and is extremely useful for system administrators.
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:
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.
Before we formally explore alternatives, we need to clarify several core concepts:
CIM cmdlets 通过 WS-Management 协议实现数据交换,该协议比 DCOM 更适合远程管理,尤其是在需要穿透防火墙时。
Get-CimInstance -ClassName CIM_ComputerSystem
该命令会显示当前计算机的系统信息,输出内容与 WMIC 命令相似。
使用 Get-CimInstance 获取系统信息
Get-CimInstance -ClassName CIM_OperatingSystem
该命令提供了操作系统的详细信息,包括系统目录、构建号和版本信息等。
虽然比较推荐使用 CIM cmdlets,但 PowerShell 同样支持直接使用 WMI 的 cmdlets。例如:
Get-WmiObject -Class Win32_Process
该命令会列出当前运行的所有进程。
使用 Get-WmiObject 查看进程列表
Get-WmiObject -Class Win32_Service | Where-Object {$_.State -eq "Running"}
该命令会筛选出所有当前正在运行的服务。
使用 Get-WmiObject 查看运行的服务
如果你之前主要使用 WMIC 进行管理任务,现在可以考虑将这些脚本转换为 PowerShell cmdlets。
PowerShell 提供了更多命令选项和更灵活的脚本功能,在多数情况下,这个转换过程直接且简单。
转换过程中,Get-Command
和Get-Help
cmdlets 能帮助你快速找到对应的 PowerShell 命令,及其使用方法。
例如,要查找所有与实例相关的可用 CIM 命令,可以使用:
Get-Command -Noun CimInstance*
使用 Get-Help
获取帮助
同时,Get-Help
命令能提供特定 cmdlet 的详细使用说明和示例,这对学习新命令非常有帮助:
Get-Help Get-CimInstance -Full
通过这种方式,你就可以逐步替换 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!