WMI

Connecting to WMI from PowerShell

Example: Establish a connection to a remote computer named 192.168.1.10 using the credentials Administrator and MySecurePass.

$username = 'Administrator';
$password = 'MySecurePass';
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword;

# Establish a session using DCOM protocol
$Opt = New-CimSessionOption -Protocol DCOM
$Session = New-CimSession -ComputerName 192.168.1.10 -Credential $credential -SessionOption $Opt -ErrorAction Stop

1. Remote Process Creation Using WMI

Example: Create a remote process to write to a text file (munrawashere.txt) on a target computer (192.168.1.10).

# Define the command to execute remotely
$Command = "powershell.exe -Command Set-Content -Path C:\munrawashere.txt -Value 'This file was created remotely'";

# Execute the command remotely
Invoke-CimMethod -CimSession $Session -ClassName Win32_Process -MethodName Create -Arguments @{
    CommandLine = $Command
}

Alternatively, using wmic:


2. Creating Services Remotely with WMI

Example: Create a service named TestService that runs the payload net user remoteuser Password123 /add on a target computer.

To stop and delete the service:


3. Creating Scheduled Tasks Remotely with WMI

Example: Create a scheduled task that adds a user (scheduleduser) to the system.


4. Installing MSI Packages Through WMI

Example: Install an MSI package named example.msi located in C:\Windows on a remote computer.

Using wmic:

Last updated