PowerShell Get-ADComputer

Gather Information from Active Directory computers based off the operating system name export to CSV and open the file.

Get-ADComputer -Properties * -filter 'OperatingSystem -Like "Windows Server*" ' |`
Select Name, OperatingSystem, Description, Enabled, IPv4Address, DistinguishedName |`

Export-Csv C:\temp\Computer-Search.csv -NoTypeInformation
Invoke-item C:\temp\Computer-Search.csv        




Step 1: Query Active Directory by OU and apply results to variable
Step 2: A "Foreach" looping through the variable and the query retuns based on the computer OS Name -Like Windows Server 2012*


    #------------- Query Active Directory by OU and apply results to variable -----------------
    $ComputersMachines=Get-ADComputer -SearchBase 'OU=MyChildOU,OU=PartentOU,DC=DomainName,DC=LOCAL' -Filter '*' | Select Name -ErrorAction Stop


    #------Da Loop through variable and pull computer names based on OS Name -Like--------
    Foreach($ComputerMachine in $ComputersMachines){
    Get-ADcomputer  $ComputerMachine.Name -Properties * | Select Name, OperatingSystem | Where-Object {$_.OperatingSystem -Like "Windows Server 2012*"} -ErrorAction Stop           
          Write-Host $_.Exception.Message    




Get computer information from Active Directory based on source file and trim white space and output to file.​

    $Computers = Get-Content C:\Temp\DoIT.txt -ErrorAction Stop

    ForEach ($Computer in $Computers){ 

        Get-ADcomputer $Computer.Trim() -Properties * | Select Name, Description, Enabled, OperatingSystem |`
        Export-csv C:\Temp\Computers2.csv -append -NoTypeInformation -ErrorAction stop


        Write-Host $_.Exception.Message


     Invoke-item C:\Temp\Computers2.csv 






A basic Active Directory query with a search base setting.


#Computer in OU

Get-ADComputer -SearchBase 'OU=Computers, dc=YourDomainNameHere,dc=local' -Filter '*' | Select Name | out-file C:\Temp\Computers.txt -Append


A basic Active Directory query with a filter on a the naming scheme.

#Computer Name Like  
Get-ADComputer -filter 'name -Like "MyCompNameScheme-*" ' | select Name | Export-Csv C:\temp\Output.txt

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator