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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The below script should get everything you have requested.
Will.
$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
}
Will.
ASKER
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_networkadapterconfig uration -ComputerName $Comp | select <<<< -ExpandProperty IPAddress
+ CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Microsoft.Pow erShell.Co mmands.Sel ectObjectC ommand
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_networkadapterconfig uration -ComputerName $Comp | select <<<< -ExpandProperty DefaultIPGateway
+ CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Microsoft.Pow erShell.Co mmands.Sel ectObjectC ommand
Unable to index into an object of type System.UInt16.
At E:\Info\Inv.ps1:24 char:48
+ 'Memory'=$ComputerMem.Tota lWidth[ <<<< 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], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nError,Mic rosoft.Pow erShell.Co mmands.New ObjectComm an
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_networkadapterconfig
+ CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Microsoft.Pow
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_networkadapterconfig
+ CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException
+ FullyQualifiedErrorId : ArgumentNull,Microsoft.Pow
Unable to index into an object of type System.UInt16.
At E:\Info\Inv.ps1:24 char:48
+ 'Memory'=$ComputerMem.Tota
+ 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], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
ASKER
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.
Will.
Yes it works correctly Will.
Thanks.
Thanks.
ASKER
will check and let you know
ASKER