Link to home
Start Free TrialLog in
Avatar of Eric Perez
Eric PerezFlag for United States of America

asked on

Powershell script to pull Info from all server within a domain

Hi,

I need help in getting a Powershell script in retrieving info from servers with in a domain OR OU and getting an output to an xlsx file.

Search through domain servers

1.  look for this in the host name "FS",  "FP", “DFS”, “RP”  in name
2. Host-name and OS of the Server.
3. if the File services is installed
4. if File service is installed show the path to shares per its server

thanks,
Eric
Avatar of Coralon
Coralon
Flag of United States of America image

This was interesting, and I had to leverage all kinds of things to pull what you are looking for.. :-)

$SearchRoot = 'DC=domain,DC=tld'
$filter = "(&(objectCategory=computer)(|(name=*fp*)(name=*fp*)(name=*dfs*)(name=*rp*)))"

$ADSI = [adsisearcher]$filter
$ADSI.SearchRoot = $SearchRoot
$ADSI.PageSize = 1000
$ADSI.SizeLimit = 1000

$Computers = $ADSI.FindAll().Properties.Name  

$Output = @()

foreach ($Computer in $Computers)
{
    $OS = invoke-command -ComputerName $Computer -scriptblock { ((Get-WmiObject -ComputerName $Computer -Class win32_operatingsystem -Property Name) -split '|')[0] }
    $FSInstalled = invoke-command -ComputerName $Computer -ScriptBlock { get-windowsfeature -Name fs* | Select-Object -property Name,Installed }
    $Shares = invoke-command -ComputerName $Computer -ScriptBlock { (Get-WmiObject -ComputerName $Computer -Class win32_share -Property path).path -join ';' }

       $Properties = @{ }
       $Properties.Add('Name',$Computer)
       $Properties.Add('OS',$OS)

    $FSInstalled | ForEach-Object {
        $Properties.Add($_.Name,$_.Installed)
    }
    
    $Properties.Add('Shares', $Shares)

    $Output += (New-Object -TypeName PSCustomObject -Property $Properties)
} 

$output | export-csv -Path "$env:temp\computerprops.txt" -NoTypeInformation 

Open in new window


It is limited to 1000 servers.. but if you have more, then you can increase the limit numbers in the script..

It's not completely tested, but it should work.  You will need to make sure you have WMI access and Powershell remoting access..

Coralon
Avatar of Eric Perez

ASKER

I am getting this error....


Exception calling "FindAll" with "0" argument(s): "Unspecified error
"
At C:\Users\adm.ep546\Desktop\ServerLook.ps1:9 char:1
+ $Computers = $ADSI.FindAll().Properties.Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : COMException
ASKER CERTIFIED SOLUTION
Avatar of Coralon
Coralon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome!!!! it worked like a charm.