dsQuery | dsGet - Results


Recommended Posts

Having issues getting the info i want from a query.

 

Basically i want to get all the computers that below to an OU - "SUP Evaluation Wrkst" ---

 

I was giving this code:

for /f "delims=" %%a in ('dsquery ou -name "SUP Evaluation Wrkst" -limit 1000') do (dsquery computer %%a >>1.txt)

but doesnt seem to be working for me.  Can someone fix it?

 

Either that or i was trying to use:

dsquery OU -name "SUP Evaluation Wrkst" -limit 1000 | DSget computer > C:\CompsInEVALOU.txt

But that fails as the target is not the same as it says (OU vs Computer)

Link to comment
Share on other sites

I'm not sure about the command line, but it can be done via Powershell.

Get-ADComputer -SearchBase 'OU=EVALOU,DC=Test,DC=Domain' -Filter {Name -Like "*"} | Select -Expand Name | Out-File C:\CompsInEVALOU.txt

If that doesn't work, you may need to use this command first to import the Active Directory module:

Import-Module ActiveDirectory

 

If you cannot import that module, you may need to install RSAT (Remote Server Administration Tools).

Link to comment
Share on other sites

Guess i should also mention, there are serveral "SUP Evaluation Wrkst" OUs for each site (think globally). So one in China under a AP/CHN/SHNH tree and some other AP/JP/TKYO containing different PCs for Tokyo.

 

So the searchbase is whats tripping me up because thats specific to a certain OU when i want it to search the Entire Domain for the OU then find the Computers within that OU.

Link to comment
Share on other sites

You'll want a function to search through AD globally to find all OU's that match your criteria on a loop then another function for each match to list machines for those OU's found and put them into a CSV/Text file/Array.

 

You can do that with Powershell just as a two part process. DS tools will likely not help unless you want to create some evil looking scripts around it.

Link to comment
Share on other sites

does your command

 

dsquery ou -name "SUP Evaluation Wrkst" -limit 1000

 

return anything?

Link to comment
Share on other sites

You'll want a function to search through AD globally to find all OU's that match your criteria on a loop then another function for each match to list machines for those OU's found and put them into a CSV/Text file/Array.

 

You can do that with Powershell just as a two part process. DS tools will likely not help unless you want to create some evil looking scripts around it.

 

Thanks, got any tips there?

 

does your command

 

dsquery ou -name "SUP Evaluation Wrkst" -limit 1000

 

return anything?

 

Yes Budman, this works just fine which is why i figured i could do a dsGET on that result.

 

Here is a snippet:

"OU=SUP Evaluation Wrkst,OU=MNC2,OU=GBR,OU=EU,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=BNGL,OU=IND,OU=AP,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=SHNH,OU=CHN,OU=AP,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=AAAD,OU=MI,OU=USA,OU=NA,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=AAMT,OU=MI,OU=USA,OU=NA,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=AART,OU=MI,OU=USA,OU=NA,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=ARAS,OU=BRA,OU=SA,OU=sites,DC=domain,DC=mycompany,DC=com"
"OU=SUP Evaluation Wrkst,OU=ARTR,OU=BEL,OU=EU,OU=sites,DC=domain,DC=mycompany,DC=com"
Link to comment
Share on other sites

Here is what I have for powershell

 

Get-ADObject -Filter { DN -like "*SUP Evaluation Wrkst*" } | Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand Name | Out-File c:\blah\blah\file.txt

 

or

 

Get-ADObject -Filter { DN -like "*SUP Evaluation Wrkst*" } | Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand Name | Out-GridView

 

or

 

Get-ADObject -Filter { DN -like "*SUP Evaluation Wrkst*" } | Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand Name

 

having an issue with export-csv...

 

If you change DN to CN it bombs at about 350 results.

 

An alternative is to

 

Get-ADObject -Filter { DN -like "*SUP Evaluation Wrkst*" } | Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand DistinguishedName | Out-File c:\blah\blah\file.txt

 

or

 

Get-ADObject -Filter { DN -like "*SUP Evaluation Wrkst*" } | Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand DistinguishedName | Out-GridView

 

 

in stead of brackets

 

 

Get-ADObject -Filter 'DN -like "*SUP Evaluation Wrkst*"' | Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand DistinguishedName | Out-GridView

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.