WMIC : Invalid Global Switch - The How and Why Cookbook

 WMIC says "Invalid Global Switch"

Why does it say that when you use the /NODE switch?  It's because WMIC really wants the full IP address of the remote computer, not the name.

Here's an example of it:


This is the right way to do it, to prevent "Invalid Global Switch"


The WMIC Cookbook

In these examples, we will write all output to a file called a.out. First one will be written, others will be appended.

# --------- CUT HERE -----------------------
# A powershell script by Uncle Joe
# To append to the file, use /APPEND instead of /OUTPUT
$username="talladega\lets_go_brandon"
$password="Nascar22"
# Get Computer Name
wmic /NODE:192.168.0.143 /OUTPUT:a.out /USER:${username} /PASSWORD:${password} computersystem get model,manufacturer,name,username
# Disk Check
wmic /NODE:192.168.0.143 /APPEND:a.out /USER:${username} /PASSWORD:${password} logicaldisk list full
# CPU Check:
wmic /NODE:192.168.0.143 /APPEND:a.out /USER:${username} /PASSWORD:${password} cpu list brief
# Check Windows Updates
wmic /NODE:192.168.0.143 /APPEND:a.out /USER:${username} /PASSWORD:${password} qfe list full
# or
wmic /NODE:192.168.0.143 /APPEND:a.out /USER:${username} /PASSWORD:${password} qfe list brief
# Get OS Version
wmic /NODE:192.168.0.143 /APPEND:a.out /USER:${username} /PASSWORD:${password} os get version,caption,FreePhysicalMemory,BuildType
# --------- CUT HERE -----------------------

Before running powershell scripts, you need to do this first:

This example shows how to set the execution policy for the local computer.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Get-ExecutionPolicy -List

Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    RemoteSigned
 LocalMachine    RemoteSigned

The Set-ExecutionPolicy cmdlet uses the ExecutionPolicy parameter to specify the RemoteSigned policy. The Scope parameter specifies the default scope value, LocalMachine. To view the execution policy settings, use the Get-ExecutionPolicy cmdlet with the List parameter.


Useful Commands Cookbook

Force a remote gpupdate from wmic
WMIC /node:ComputerName process call create “cmd.exe /c GPUpdate.exe”

Select Process Using the Most Memory

Use Sort-Object and Select-Object to sort and select lines.
Get-Process | Sort-Object -Property WS | Select-Object -Last 5

Use the Split Operator to cut up text

$text = "Description=The '=' character is used for assigning values to a variable"
$name, $value = $text -split "=", 2

@"
Name  =  $name
Value =  $value
"@


Comments

Popular posts from this blog

Microsoft Visio 2010 Premium Product Keys

Mercedes Benz Diesel CDI EGR Emulator Circuit Diagrams

Fix: The Diagnostic Service Host service failed to start due to the following error. [ solved, no kidding ]