Solved trying to convert WMIC to Powershell


bonky

Member
Local time
1:42 PM
Posts
24
OS
win10
hi alll

for /f "tokens=2,3 delims={,}" %a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do if not defined ip set ip=%~a

trying to convert this to powershell....

is any one able to help?
 

My Computer

System One

  • OS
    win10
    Computer type
    PC/Desktop
Code:
@echo off
for /f "tokens=1" %%a in ('powershell "Get-CimInstance Win32_NetworkAdapterConfiguration | Where-Object { $_.DefaultIPGateway -ne $null } | Select-Object -ExpandProperty DefaultIPGateway"') do if not defined ip set ip=%%~a
echo %ip%
 

My Computer

System One

  • OS
    Windows 7
Code:
@echo off
for /f "tokens=1" %%a in ('powershell "Get-CimInstance Win32_NetworkAdapterConfiguration | Where-Object { $_.DefaultIPGateway -ne $null } | Select-Object -ExpandProperty DefaultIPGateway"') do if not defined ip set ip=%%~a
echo %ip%
Thank you... Thank you so much!!
 

My Computer

System One

  • OS
    win10
    Computer type
    PC/Desktop
for /f "usebackq tokens=*" %G in (`powershell -NoProfile -Command "foreach ($a in Get-WmiObject Win32_NetworkAdapterConfiguration DefaultIPGateway -Filter 'IPEnabled = TRUE') { if ($a.DefaultIPGateway) { $a.DefaultIPGateway[0]; break } }"`) do set "ip=%G"
 

My Computers

System One System Two

  • OS
    11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Asus TUF Gaming F16 (2024)
    CPU
    i7 13650HX
    Memory
    16GB DDR5
    Graphics Card(s)
    GeForce RTX 4060 Mobile
    Sound Card
    Eastern Electric MiniMax DAC Supreme; Emotiva UMC-200; Astell & Kern AK240
    Monitor(s) Displays
    Sony Bravia XR-55X90J
    Screen Resolution
    3840×2160
    Hard Drives
    512GB SSD internal
    37TB external
    PSU
    Li-ion
    Cooling
    2× Arc Flow Fans, 4× exhaust vents, 5× heatpipes
    Keyboard
    Logitech K800
    Mouse
    Logitech G402
    Internet Speed
    30Mbit/s up, 500Mbit/s down
    Browser
    FF
    Antivirus
    What's an antivirus?
  • Operating System
    11 Home
    Computer type
    Laptop
    Manufacturer/Model
    Medion S15450
    CPU
    i5 1135G7
    Memory
    16GB DDR4
    Graphics card(s)
    Intel Iris Xe
    Sound Card
    Eastern Electric MiniMax DAC Supreme; Emotiva UMC-200; Astell & Kern AK240
    Monitor(s) Displays
    Sony Bravia XR-55X90J
    Screen Resolution
    3840×2160
    Hard Drives
    2TB SSD internal
    37TB external
    PSU
    Li-ion
    Keyboard
    Logitech K800
    Mouse
    Logitech G402
    Internet Speed
    30Mbit/s up, 500Mbit/s down
    Browser
    FF
Back
Top Bottom