可能是一个愚蠢的问题,但我只是好奇。
Get-CIMInstance为类下的应用程序调用卸载和Get-WMIObject调用卸载之间有区别Win32_Product吗?我问的唯一原因是因为:
Get-CIMInstance用于卸载应用程序,将使用某些程序重新启动我的计算机。- 用于卸载应用
Get-WMIObject程序无需重新启动即可运行。
此外,将 aGet-Member连接到任何Get-CIMInstance产品都不会给我提供卸载方法,但它确实使用Get-WMIObject. 开发人员就是这样写的吗?虽然,Invoke-CIMMethod -Name Uninstall仍然有效。
获取 CIMInstance / 卸载
Get-CIMInstance下面是我使用/卸载多个应用程序的操作Invoke-CIMMethod -Name Uninstall:
Get-CimInstance -ClassName win32_product | Where-Object Name -Match "Visual" |
ForEach-Object -Process {
Invoke-CimMethod -InputObject $_ -Name Uninstall
}
#Methods Returned
<#
Get-CimInstance -ClassName win32_product | Where-Object Name -Match "Visual" | Get-Member -MemberType Method
TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_Product
Name MemberType Definition
---- ---------- ----------
Clone Method System.Object ICloneable.Clone()
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetCimSessionComputerName Method string GetCimSessionComputerName()
GetCimSessionInstanceId Method guid GetCimSessionInstanceId()
GetHashCode Method int GetHashCode()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Ser...
GetType Method type GetType()
ToString Method string ToString()
#>
获取 WMIObject / 卸载
Get-WMIObject -ClassName win32_product | Where-Object Name -Match "Visual" |
ForEach-Object -Process {
Invoke-WMIMethod -InputObject $_ -Name Uninstall
}
#Methods Returned
<#
Get-WMIObject -Class win32_product | Where-Object Name -Match "Visual" | Get-Member -MemberType Method
TypeName: System.Management.ManagementObject#root\cimv2\Win32_Product
Name MemberType Definition
---- ---------- ----------
Configure Method System.Management.ManagementBaseObject Configure(System.UInt16 InstallState, System.UInt16 InstallLevel, S...
Reinstall Method System.Management.ManagementBaseObject Reinstall(System.UInt16 ReinstallMode)
Uninstall Method System.Management.ManagementBaseObject Uninstall()
Upgrade Method System.Management.ManagementBaseObject Upgrade(System.String PackageLocation, System.String Options)
#>
请原谅长篇大论,只是一个好奇的头脑。
如果不允许,请删除/关闭。