Hostname batch script.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nazha
Posts: 1
Joined: 17 Jul 2011 03:14

Hostname batch script.

#1 Post by nazha » 17 Jul 2011 03:21

Dear all Sifu,

Anyone know how to do a batch script got filter the hostname ?


like in my environment my workstation name

"KL-Petronas-Marketing-001"
"JB-TowerB-Sales-001"
"A-PN-Support-001"

The Hostname Format is "Location-Building-Department-PC"
But using Hyphen to separate which value

I just want the
"KL-Petronas"
"JB-TowerB"
"A-PN"

Thank you.. deeply appreciate.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Hostname batch script.

#2 Post by Ed Dyreen » 17 Jul 2011 06:33

'

Code: Select all

@echo off

set $var=KL-Petronas-Marketing-001

for /f "tokens=1,2 delims=-" %%a in ( "%$var%" ) do echo.token=%%a-%%b_

pause
exit /b

Post Reply