Solved

Batch command to get FQDN of COMPUTER ala %userdnsdomain%

Posted on 2014-03-27
12
2,432 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

729 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