Solved

Batch command to get FQDN of COMPUTER ala %userdnsdomain%

Posted on 2014-03-27
12
2,160 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
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 28

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 18

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
 
LVL 18

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 28

Expert Comment

by:becraig
ID: 39960247
for /f "tokens=*" %%a in ('powershell "(gwmi WIN32_ComputerSystem).Domain"') do set var=%%a
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 18

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 39

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 28

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 39

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 28

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now