locked
getting a for loop to pull a domain name RRS feed

  • Question

  • so I have been attempting to get a script to pull just the domain name for use as a variable however I am having issues getting the for loop to just grab the domain name.

    Here is my script

    set "DOMCMD=wmic computersystem get domain | findstr /v /i /c:"Domain""
    for /f %%a in ('"%DOMCMD%"') do set "DOMAIN=%%a
    
    Any suggestions on what I could attempt?


    Wednesday, June 8, 2016 1:45 AM

Answers

  • so I have been attempting to get a script to pull just the domain name for use as a variable however I am having issues getting the for loop to just grab the domain name.

    Here is my script

    set "DOMCMD=wmic computersystem get domain | findstr /v /i /c:"Domain""
    for /f %%a in ('"%DOMCMD%"') do set "DOMAIN=%%a
    Any suggestions on what I could attempt?


    The domain is:

    echo %userdomain%

    Why would you not use it?


    \_(ツ)_/

    • Marked as answer by Kalamarii_ Wednesday, June 8, 2016 2:38 AM
    Wednesday, June 8, 2016 2:16 AM

All replies

  • Using PowerShell

    $Domain = (Get-WmiObject -namespace "root\CIMV2" -Class Win32_ComputerSystem).Domain


    Wednesday, June 8, 2016 2:04 AM
  • so I have been attempting to get a script to pull just the domain name for use as a variable however I am having issues getting the for loop to just grab the domain name.

    Here is my script

    set "DOMCMD=wmic computersystem get domain | findstr /v /i /c:"Domain""
    for /f %%a in ('"%DOMCMD%"') do set "DOMAIN=%%a
    Any suggestions on what I could attempt?


    The domain is:

    echo %userdomain%

    Why would you not use it?


    \_(ツ)_/

    • Marked as answer by Kalamarii_ Wednesday, June 8, 2016 2:38 AM
    Wednesday, June 8, 2016 2:16 AM
  • Using PowerShell

    $DOMAIN=[System.Net.DNS]::GetHostByName('').HostName

    Using Powershell

    $env:USERDOMAIN


    \_(ツ)_/

    Wednesday, June 8, 2016 2:17 AM
  • Need to acquire the .com .local but the environment variable works for what i am working on currently.
    Wednesday, June 8, 2016 2:38 AM
  • echo %userdnsdomain%


    \_(ツ)_/

    Wednesday, June 8, 2016 3:45 AM