SQLvariations: SQL Server, a little PowerShell, maybe some Hyper-V Rotating Header Image

November, 2011:

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

My First MSSQLTip!

Today my first ever MSSQLTip was published.  Before you ask: Yes, it talked about PowerShell. It came about because some of the SQL MVPs were trying to figure out the best way to download a VM that had been split up into 36 different equal-sized files.  I’m sure there’s a better way than this but at the same time it took me about 4 minutes to write.  Write is the wrong term, more like copy/paste/change a few things. Give it a whirl and let me know what you think!