Wmi Class | MSBuild Extension Pack Help 4.0.12.0 |
Valid TaskActions are:
Execute (Required: Class, Namespace, Method Optional: Instance, MethodParameters Output: ReturnValue)
Query (Required: Class, Properties Output: Info (ITaskItem))
Remote Execution Support: Yes
Inheritance Hierarchy
MSBuild.ExtensionPackBaseTask
MSBuild.ExtensionPack.ManagementWmi
Namespace: MSBuild.ExtensionPack.Management
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0
The Wmi type exposes the following members.
Constructors
Name | Description | |
---|---|---|
Wmi |
Properties
Name | Description | |
---|---|---|
Class |
Sets the WMI class.
| |
Info |
Gets the WMI info.
| |
Instance |
Sets the Wmi Instance used in Execute
| |
Method |
Sets the Method used in Execute
| |
MethodParameters |
Sets the MethodParameters. Use #~# separate name and value.
| |
Namespace |
Sets the namespace.
| |
Properties |
An Item Collection of Properties to get
| |
ReturnValue |
Gets the ReturnValue for Execute
|
Examples
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath> <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath> </PropertyGroup> <Import Project="$(TPath)"/> <Target Name="Default"> <ItemGroup> <WmiProps Include="BIOSVersion"/> <WmiProps Include="CurrentLanguage"/> <WmiProps Include="Manufacturer"/> <WmiProps Include="SerialNumber"/> <Wmi2Props Include="InstanceName"/> <!-- Note that #~# is used as a separator--> <WmiExec Include="Description#~#ExtensionPack Description"/> <WmiExec2 Include="Name#~#MyNewShare;Path#~#C:\demo;Type#~#0"/> <WmiExec3 Include="CommandLine#~#calc.exe"/> </ItemGroup> <!-- Start the Calculator --> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Execute" Class="Win32_Process" Method="Create" MethodParameters="@(WmiExec3)" Namespace="\root\CIMV2"> <Output TaskParameter="ReturnValue" PropertyName="Rval2"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="ReturnValue: $(Rval2)"/> <!-- Create a share --> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Execute" Class="Win32_Share" Method="Create" MethodParameters="@(WmiExec2)" Namespace="\root\CIMV2"> <Output TaskParameter="ReturnValue" PropertyName="Rval2"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="ReturnValue: $(Rval2)"/> <!-- Set share details using the WmiExec ItemGroup info--> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Execute" Class="Win32_Share" Method="SetShareInfo" Instance="Name='ashare'" MethodParameters="@(WmiExec)" Namespace="\root\CIMV2"> <Output TaskParameter="ReturnValue" PropertyName="Rval"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="ReturnValue: $(Rval)"/> <!-- Stop a service --> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Execute" Class="Win32_Service" Method="StopService" Instance="Name='SQLSERVERAGENT'" Namespace="\root\CIMV2"> <Output TaskParameter="ReturnValue" PropertyName="Rval2"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="ReturnValue: $(Rval2)"/> <!-- Query the Bios properties --> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Query" Class="Win32_BIOS" Properties="@(WmiProps)" Namespace="\root\cimv2"> <Output TaskParameter="Info" ItemName="Info"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="WMI Info for Win32_BIOS on %(Info.Identity): BIOSVersion=%(Info.BIOSVersion), CurrentLanguage=%(Info.CurrentLanguage), Manufacturer=%(Info.Manufacturer), SerialNumber=%(Info.SerialNumber)"/> <!-- Query the server settings properties --> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Query" Class="ServerSettings" Properties="@(Wmi2Props)" Namespace="\root\Microsoft\SqlServer\ComputerManagement"> <Output TaskParameter="Info" ItemName="Info2"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="WMI Info for ServerSettings on %(Info2.Identity): InstanceName=%(Info2.InstanceName)"/> <!-- Query a remote server --> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Query" MachineName="AREMOTESERVER" UserName="ADOMAIN\AUSERNAME" UserPassword="APASSWORD" Class="Win32_BIOS" Properties="@(WmiProps)" Namespace="\root\cimv2"> <Output TaskParameter="Info" ItemName="Info2"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="WMI Info for %(Info2.Identity): BIOSVersion=%(Info2.BIOSVersion), CurrentLanguage=%(Info2.CurrentLanguage), Manufacturer=%(Info2.Manufacturer), SerialNumber=%(Info2.SerialNumber)"/> <!-- Let's stop Paint.net --> <ItemGroup> <WmiProps2 Include="Name"/> <WmiProps2 Include="ProcessID"/> </ItemGroup> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Query" Class="Win32_Process WHERE Name='paintdotnet.exe'" Namespace="\root\CIMV2" Properties="@(WmiProps2)" MachineName="192.168.0.6"> <Output TaskParameter="Info" ItemName="Info"/> </MSBuild.ExtensionPack.Management.Wmi> <Message Text="WMI Info for Win32_Processes: Name: %(Info.Name), ProcessID: %(Info.ProcessID)"/> <Message Text="Stopping Paint.NET" Condition="%(Info.ProcessID) != ''"/> <MSBuild.ExtensionPack.Management.Wmi TaskAction="Execute" Class="Win32_Process" Method="Terminate" Namespace="\root\CIMV2" Instance="Handle=%(Info.ProcessID)" MachineName="192.168.0.6" Condition="%(Info.ProcessID) != ''"/> </Target> </Project>
See Also