Link to home
Start Free TrialLog in
Avatar of jmohan0302
jmohan0302

asked on

Gather remote computer system and disk information via script

I am looking for a script to get the server information for a list of servers. The output should be in a CSV format and the output should contain the following columns or Fields:

Server Name, Manufacturer,Model, OS Name, OS Version, Service Pack No. of CPU, Cores, RAM, IP Address, Subnet Mask, Default Gateway, C:\ DiskSpace D:\ Diskspace, Is Cluster Cluster Name

For drives the script should provide the diskspace details for all the drives..... say for example  server A may have C:\ drive, E:\drive and another server B may have C:\ drive, E: \drive and F:\ drive so the output should provide for the C: drive and E: drive diskspace for Server A and for Server B the output should be C:\ drive E: drive and F: drive.

For cluster, if server is part of cluster then the output should provide for Is Cluster field is Yes and for cluster name, the name of the cluster

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Maidine Fouad
Maidine Fouad
Flag of Morocco 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
Avatar of jmohan0302
jmohan0302

ASKER

Thanks Fouad. Howeve, I am looking for the desired output and serverlist should be for a list of servers and not for all the servers in domain. Thanks
Avatar of Will Szymkowski
The below script should get everything you have requested.

$Log = "c:\filename.csv"
$Computers = Get-Content "c:\filename.txt"

ForEach ($Comp in $Computers) 
    {

$ComputerSystem = Get-WmiObject -Class win32_computersystem -ComputerName $Comp
$ComputerOS = Get-WmiObject -Class win32_operatingsystem -ComputerName $Comp
$ComputerCPU = Get-WmiObject -Class win32_processor -ComputerName $Comp
$ComputerMem = Get-WmiObject -Class win32_physicalmemory -ComputerName $Comp
$ComputerIP = Get-WmiObject -Class win32_networkadapterconfiguration -ComputerName $Comp | select -ExpandProperty IPAddress
$ComputerGW = Get-WmiObject -Class win32_networkadapterconfiguration -ComputerName $Comp | select -ExpandProperty DefaultIPGateway
$ComputerDisk = Get-WmiObject -Class win32_logicaldisk -ComputerName $Comp | ? {$_.DriveType -eq "3"}
$ComputerCluster = Get-WmiObject -Class mscluster_resource -Namespace root\mscluster -ErrorAction SilentlyContinue -ComputerName $Comp

    $Data = [ordered]@{
              'ServerName'=$ComputerSystem.Name;
              'Manufacturer'=$ComputerSystem.Manufacturer;
              'Model'=$ComputerSystem.Model;
              'OS Name'=$ComputerOS.Caption;
              'Service Pack'=$ComputerOS.CSDVersion;
              'Total CPUs'=$ComputerCPU.CpuStatus;
              'Total Cores'=$ComputerCPU.NumberOfCores;
              'Memory'=$ComputerMem.TotalWidth[0];
              'IPAddress'=$ComputerIP[0,1,2,3,4];
              'Default Gateway'=$ComputerGW;
              'Drive Letter'=$ComputerDisk.DeviceID[0,1,2,3];
              'Free Space(GB)'=$ComputerDisk | ForEach-Object {[math]::Truncate($_.freespace / 1GB)};
              'Total Size (GB)'=$ComputerDisk | ForEach-Object {[math]::Truncate($_.Size / 1GB)};
              'Cluster Name'=$ComputerCluster.Name;
            }

        $DataOut = New-Object -TypeName PSObject -Property $Data

        $DataOut | Out-File $Log -append


}

Open in new window


Will.
Will,

thanks. I am getting following error, when executing, thanks

elect-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value.
At E:\Info\Inv.ps1:11 char:98
+ $ComputerIP = Get-WmiObject -Class win32_networkadapterconfiguration -ComputerName $Comp | select <<<<  -ExpandProperty IPAddress
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], PSArgumentNullException
    + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand
 
Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value.
At E:\Info\Inv.ps1:12 char:98
+ $ComputerGW = Get-WmiObject -Class win32_networkadapterconfiguration -ComputerName $Comp | select <<<<  -ExpandProperty DefaultIPGateway
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], PSArgumentNullException
    + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand
 
Unable to index into an object of type System.UInt16.
At E:\Info\Inv.ps1:24 char:48
+               'Memory'=$ComputerMem.TotalWidth[ <<<< 0];
    + CategoryInfo          : InvalidOperation: (0:Int32) [], RuntimeException
    + FullyQualifiedErrorId : CannotIndex
 
New-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At E:\Info\Inv.ps1:33 char:59
+         $DataOut = New-Object -TypeName PSObject -Property <<<<  $Data
    + CategoryInfo          : InvalidData: (:) [New-Object], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewObjectComman
Any Update????
Does this provide any results? Works completely fine in my lab. What are you putting in your txt file? Have you tried to just add one computer to the txt file and see if that works? Also make sure that the machines is online and pingable.

Will.
Yes it works correctly Will.
Thanks.
will check and let you know