Author Posts

May 18, 2014 at 10:16 pm

Hi,

This is the script i run

$KRErrorLogPreferance = "E:\Education\BIT\MCSA\Powershell\CBT Tool Making Code"

function Get-SystemInfo{
< # .SYNOPSIS Quieries critical information from a single computer .DESCRIPTION Quiries OS and the Hardware information from a single computer. This Utilize WMI Objects,so appropriate WMI port must be open and you must be admin on the remort machine .PARAMETER ComputerName The computer name to query, accept multiple values and pipeline input .PARAMETER IPAddress Enter the IP Address to query, pipeline is not accepted .EXAMPLE Get-SystemInfo.ps1 -ComputerName WHATEVER This will query infromation from the computer WHATEVER .EXAMPLE Get-SystemInfo.ps1 -ComputerName WHATEVER | Format-Table * This will display the information as a table #>

[CmdletBinding()]

Param(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ParameterSetName='computername',
ValueFromPipelineByPropertyName=$True,
HelpMessage="Enter the computer name to qury WMI object")]
[Alias('hostname')]
[ValidateLength(4,15)]
[string[]]$ComputerName,

[Parameter(Mandatory=$True,
HelpMessage="Enter the IP Address to query WMI Object",
ParameterSetName='ip')]
[ValidatePattern('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')]
[string[]]$IPAddress,

[Parameter()]
[string]$ErrorLogFilePath =$KRErrorLogPreferance
)

BEGIN{
if($PSBoundParameters.ContainsKey('ipaddress')){
$ComputerName=$IPAddress
}
}

PROCESS{

foreach($computer in $ComputerName){

Write-Verbose "Connecting via WMI $computer"

$os=Get-WmiObject win32_OperatingSystem -ComputerName $computer
$cs=Get-WmiObject win32_computerSystem -ComputerName $computer

Write-Verbose "Finished with WMI building output"

$props =@{'ComputerName'=$computer;
'OSVersion'= $os.version;
'OSBuild'=$os.BuildNumber;
'SPVersion'=$os.ServicePackMajorVersion;
'Model'=$cs.Model;
'Manufacture'=$cs.Manufacturer;
'RAM'=$cs.TotalPhysicalMemory / 1GB -as [int]
'Sockets'=$cs.NumberOfProcessors;
'Cores'=$cs.NumberOfLogicalProcessors
}

$obj = New-Object -TypeName PSObject -Property $props

Write-Verbose "Outputing to pipeline "

Write-Output $obj

}
}

END{}
}

#Get-SystemInfo -ComputerName localhost
#'kasunrajapakse','localhost','kasunrajapakse' | Get-SystemInfo
#Import-Csv -Path 'E:\Education\BIT\MCSA\PowerShell\CBT Tool Making Code\computers.csv' | Get-SystemInfo
Get-SystemInfo -IPAddress 127.0.0.0.1 -Verbose

When i run it using ipaddress parameter it gives me the following error

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:57 char:17
+ $os=Get-WmiObject win32_OperatingSystem -ComputerName $computer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Please help me !!!

May 18, 2014 at 11:01 pm

The IP address 127.0.0.0.1 you've provided is not valid. One .0 octet too much.

Try again with:
Get-SystemInfo -IPAddress 127.0.0.1 -Verbose

Verify "localhost" address:
ping -4 localhost

May 18, 2014 at 11:51 pm

oh i see it thanks for pointing it to me 🙂