Link to home
Create AccountLog in
Scripting Languages

Scripting Languages

--

Questions

--

Followers

Top Experts

Avatar of levertm
levertm🇨🇦

Batch command to get FQDN of COMPUTER ala %userdnsdomain%
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

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of becraigbecraig🇺🇸

(gwmi WIN32_ComputerSystem).Domain

or

$computer = Get-WmiObject -Class Win32_ComputerSystem


member .Domain

$computer.Domain

Avatar of levertmlevertm🇨🇦

ASKER

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.

Avatar of Raheman M. AbdulRaheman M. Abdul🇬🇧

$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"

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Raheman M. AbdulRaheman M. Abdul🇬🇧

$command=Your powershell cmdlets here"
powershell $command > myTmpFile
set /p PcFQDN= < myTmpFile
del /q myTmpFile

echo %PcFQDN%

Avatar of levertmlevertm🇨🇦

ASKER

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.

Avatar of becraigbecraig🇺🇸

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

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Raheman M. AbdulRaheman M. Abdul🇬🇧

Try this:

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

echo %PcFQDN%

Avatar of footechfootech🇺🇸

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"

ASKER CERTIFIED SOLUTION
Avatar of becraigbecraig🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of footechfootech🇺🇸

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").

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of becraigbecraig🇺🇸

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.

Avatar of levertmlevertm🇨🇦

ASKER

You're right becraig, my user and computer are in separate domains.

Your solution worked, thank you,
Scripting Languages

Scripting Languages

--

Questions

--

Followers

Top Experts

A scripting language is a programming language that supports scripts, programs written for a special run-time environment that automate the execution of tasks that could alternatively be executed one-by-one by a human operator. Scripting languages are often interpreted (rather than compiled). Primitives are usually the elementary tasks or API calls, and the language allows them to be combined into more complex programs. Environments that can be automated through scripting include software applications, web pages within a web browser, the shells of operating systems (OS), embedded systems, as well as numerous games. A scripting language can be viewed as a domain-specific language for a particular environment; in the case of scripting an application, this is also known as an extension language.