?
Solved

Batch command to get FQDN of COMPUTER ala %userdnsdomain%

Posted on 2014-03-27
12
Medium Priority
?
2,502 Views
Last Modified: 2014-03-28
Hello,

I have the following batch file that calls up powershell, it works wonderfully. I now need to modify it to grab the computer FQDN instead of the user FDQN in the -Domain parameter.

How can I achieve this?

Powershell.exe -executionpolicy unrestricted -File C:\temp\gpo\source\2\import_gpos.ps1 -SomInfo -Domain %USERDNSDOMAIN% -backupfolder "C:\temp\gpo\source\2"

Open in new window

0
Comment
Question by:levertm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 39960205
(gwmi WIN32_ComputerSystem).Domain

or

$computer = Get-WmiObject -Class Win32_ComputerSystem


member .Domain

$computer.Domain
0
 

Author Comment

by:levertm
ID: 39960209
Hi again craig!

I know of (gwmi WIN32_ComputerSystem).Domain and use it in my other powershell scripts but how can I insert that into my batch file? batch wont recognize it.
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39960211
$objIPProperties = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()

$computerFQDN="{0}.{1}" -f $objIPProperties.HostName, $objIPProperties.DomainName

Powershell.exe -executionpolicy unrestricted -File C:\temp\gpo\source\2\import_gpos.ps1 -SomInfo -Domain $computerFQDN -backupfolder "C:\temp\gpo\source\2"
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39960228
$command=Your powershell cmdlets here"
powershell $command > myTmpFile
set /p PcFQDN= < myTmpFile
del /q myTmpFile

echo %PcFQDN%
0
 

Author Comment

by:levertm
ID: 39960233
Hi Wizard,

That's giving me errors:

$objlproperties is not recognized as an internal or external command, operable program or batch file.

$ComputerFQDN is not recognized as an internal or external command, operable program or batch file.
0
 
LVL 29

Expert Comment

by:becraig
ID: 39960247
for /f "tokens=*" %%a in ('powershell "(gwmi WIN32_ComputerSystem).Domain"') do set var=%%a
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39960257
Try this:

powershell -command "(gwmi WIN32_ComputerSystem).Domain" > myTmpFile
set /p PcFQDN= < myTmpFile
del /q myTmpFile

echo %PcFQDN%
0
 
LVL 40

Expert Comment

by:footech
ID: 39960277
Just modify your batch file to include this line
set FQDN=%computername%.%userdnsdomain%

Then your next line would be
Powershell.exe -executionpolicy unrestricted -File C:\temp\gpo\source\2\import_gpos.ps1 -SomInfo -Domain %FQDN% -backupfolder "C:\temp\gpo\source\2"
0
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 39960289
Foo I think the problem is he does not want the user domain.

What I gave him would work perfectly

for /f "tokens=*" %%a in ('powershell "(gwmi WIN32_ComputerSystem).Domain"') do set  FQDN=%%a

Open in new window

0
 
LVL 40

Expert Comment

by:footech
ID: 39960332
Perhaps you're right.  I interpreted the question to mean that he wanted the FQDN of the computer (i.e. something like "computername.domain.com").
0
 
LVL 29

Expert Comment

by:becraig
ID: 39960344
That is what he is after but based on his comment:

I now need to modify it to grab the computer FQDN instead of the user FDQN in the -Domain parameter.

I think he might have an environment where user and computer accounts are in separate domains, I might be wrong but that is the impression I get.
0
 

Author Comment

by:levertm
ID: 39961496
You're right becraig, my user and computer are in separate domains.

Your solution worked, thank you,
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question