1

I have bulk computer list in my CSV file with header of servers.

All these servers are different domains under single forest.

I need to get all these server attribute details like name and operating system, status.

I have created below script but that's not working..

Any help would be appreciated.

Import-Module ActiveDirectory

# For each domain in the forest

$domains = (Get-ADForest).Domains
$servers = Import-Csv "D:\temp\computer.csv" | % {$_.server}

foreach ($server in $servers)
{
  foreach ($domain in $domains)
  {
    Get-ADComputer $server -Server $domain -Properties operatingsystem | select name,operatingsystem 
  }
}
#

HI

I have added my script like below:

#
Import-Module ActiveDirectory



# For each domain in the forest



$domains = (Get-ADForest).Domains

$servers = Import-Csv "D:\temp\computers.csv" | % {$_.server}

$DomainController = "DC2:3268"  #  3268 is the commen port of global catalogue

$SearchBase = ((Get-ADDomain (Get-ADForest).RootDomain).DistinguishedName)

foreach ($server in $servers)

{

foreach ($domain in $domains)

{

Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem

}
}
#

Getting below error now and also I have specified only samaccountname of computer not FQDS this time..

#### Error
Get-ADComputer : A positional parameter cannot be found that accepts argument 'DPS002'.
At D:\temp\search_computer.ps1:34 char:5
+     Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
2
  • 3
    Please be more specific than "that's not working". What did you expect? What happened? Oct 26, 2015 at 13:52
  • I don't suppose the member domain is a column in your csv?
    – Matt
    Oct 26, 2015 at 14:09

1 Answer 1

2

You have to run your request against the global catalogue to find AD objects in the whole AD forest.

  1. You need a server witch is supporting global catalogue. Choose one which is next to you.

    Import-Module ActiveDirectory
    @((Get-ADForest).GlobalCatalogs) | Sort-Object
    
  2. Your script, a little bit modified

    Import-Module ActiveDirectory
    $DomainController = "ServerFromStep1:3268"  #  3268 is the commen port of global catalogue
    $SearchBase       = ((Get-ADDomain (Get-ADForest).RootDomain).DistinguishedName)
    
    foreach ($server in $servers)
    {
        Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem
    }
    
  3. The same as 2 but able to processed FQDNs from server list.

    foreach ($serverFQDN in $servers)
    {
        $Local:ServerName = (($serverFQDN -replace "\..*$", "").Trim())
        if ($ServerName) {
            Get-ADComputer $ServerName -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem
        }
    }
    
4
  • Hi I have tried script like below but got below error : Import-Module ActiveDirectory $DomainController = "DC41:3268" # 3268 is the commen port of global catalogue $SearchBase = ((Get-ADDomain (Get-ADForest).RootDomain).DistinguishedName) $servers = Import-Csv "D:\temp\computers.csv" foreach ($server in $servers) { Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Properties operatingsystem | select name,operatingsystem }
    – Mr. Chand
    Oct 26, 2015 at 18:00
  • Error is below #############ERROR ######## Get-ADComputer : A positional parameter cannot be found that accepts argument '@{server=JANCNB.accenture.com}'. At D:\temp\findallcomputers.ps1:8 char:5 + Get-ADComputer $server -Server $DomainController -SearchBase $SearchBase -Pr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
    – Mr. Chand
    Oct 26, 2015 at 18:05
  • It can't work when you are using the FQDN of a server instead of the hostname. Get-ADComputer doesn't work with FQDNs. Step 3 shows you the way out of this problem.
    – Buxmaniak
    Oct 27, 2015 at 14:35
  • @Mr.Chand please edit the original question and add your comments there as an update, include the version of the script (code) and the error there. Oct 27, 2015 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.