Quick Blog: Grabbing basic machine info with PowerShell

The other day I needed to track down how much RAM a couple of our servers had installed.  A few days later I needed to verify that a couple of them were in fact 64-bit and not 32-bit.  I decided I wanted to be able to get at this basic info any time that I wanted without having to remember all the syntax so I built it into a PowerShell function.

Building a PowerShell function is almost as easy easier than building a stored procedure around a select statement in SQL.  The reason PowerShell is easier than SQL is that when you have a parameter that you are passing in, you can give it a data type, but you don’t have to.

For the function below I gave it a default value of the local machine but you can pass in a machine name that you are trying to get to.

Just copy the code below into an ISE window and hit F5.

function Get-MachineInfo($ServerName="localhost")             
{            
get-wmiobject win32_computersystem -ComputerName $ServerName |            
select DNSHostName, Manufacturer, Model, SystemType ,             
        @{Name="TotalPhysicalMemoryInMB";Expression={"{0:n2}" -f($_.TotalPhysicalMemory/1mb)}},             
        NumberOfLogicalProcessors, NumberOfProcessors, CurrentTimeZone, DaylightInEffect            
}# End Get-MachineInfo

After you’ve done that, to call the stored proc function simply type in the name ( Get-MachineInfo ) to the prompt at the bottom and hit enter

image

Please Share This:

You may also like:

2 Responses

  1. tried it but I’m getting the following error

    Select-Object : A positional parameter cannot be found that accepts argument ‘System.Object[]’.
    At line:4 char:7
    + select <<<< DNSHostName, Manufacturer, Model, SystemType , ` @{Name="TotalPhysicalMemoryInMB";Expression={"{0:n2}" -f($_.TotalPhysicalMemory/1mb)}}, ` N
    umberOfLogicalProcessors, NumberOfProcessors, CurrentTimeZone, DaylightInEffect
    + CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

    1. Sorry about that, seems there was a problem rendering the colored version of the code. I have made an adjustment and it looks like it’s being rendered properly now. Please let me know if that fixes it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow:

Subcribe to Blog Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

What I'm Saying on Twitter

Subscribe via feedburner

%d bloggers like this: