I am trying to get the path for the OU my laptop is currently in. Here is what I have
gpresult /r /scope computer >> c:\temp\ou.txt
FIND "CN=" "C:\Temp\ou.txt" > C:\Temp\ou1.txt
The output is CN=My-PC,OU=Computers,OU=Information Technology,OU=XXXXXXX,OU=Corporate,DC=XXXXXXXX,DC=com
What I need to do is get the CN=MY-PC and extract the CN= The names will be different every time, so I need from the first , back to the beginning of the line
I havent found anything that gets me close.
Does anyone have any idea how to get the desired output?
Edited to answer Ricardo Desired output is My-pc stored as a variable %My-pc%
FOR /F
loops to split out tokens like stackoverflow.com/a/40784439/7411885. If you can use powershell, then$MyPC = (Get-Content c:\temp\ou.txt | Select-String 'CN=(.*?),').Matches.Groups[1].Value
is pretty simple.hostname
? There are some better ways even if you need to look up with AD/ldap.gpresult
can also dump to xml or html if you want better data formatting