Querying WMI with a Timeout

This is thanks to my coworker Keith Munson, who is at least as passionate and adept at PSH as I am:   function Get-WmiObjectWithTimeout {     <#     Credit to Keith Munson for this.     #>       param(         [string]$Class,         [string]$ComputerName = $env:COMPUTERNAME,         [string]$NameSpace = ‘root\cimv2’,         [System.Management.ConnectionOptions]$ConnectionOptions = $null,         [System.Management.EnumerationOptions]$EnumerationOptions…

0

Reinventing the Wheel: Get-WmiChildNamespace and Get-WmiChildPropertyData

I love and hate WMI.  I love how it offers the ability to access so many parts of the OS that PowerShell has not (yet) exposed via cmdlet.  I hate how the taxonomy is so deep, how you need to know what you’re looking for to find it. Also, I’ve been having a hard time…

0

HP Power Supplies

HP servers have redundant power supplies.  SCOM will tell me which one is broken if it’s down, but in this case, I lost power to one side of the rack, and want to see if replacing the distribution unit fixed the issue.  Here’s a quick-and-dirty WMI wrapper to do that: function Get-HPPowerSupplyStatus { param (…

0

WMI and HP Product IDs

An HP Product ID is related to the hardware SKU The plain-English way of getting the SKU is Get-WMIObject –ComputerName $computerName Win32_ComputerSystem However, our inventory system uses the HP product ID property stuffed in ILO.  As someone who uses the test lab, this isn’t something that I need to know, but one of the lab…

0

WMI-Less Network Adapters

We can get a list of network adapters (calling them NICs is a bit outdated: the C in NIC stands for ‘card’, like it’s something you plug into an ISA or PCI slot.  These days, it’s almost always built in) from Get-WMI Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration, but per http://msdn.microsoft.com/en-us/library/aa394216%28v=vs.85%29.aspx it’s being deprecated.  We should now use…

0

Getting User Names for Processes

Sometimes, I am in awe at the PowerShell team.  Other times, I am stunned, but at their inability to grasp common user scenarios.  PSH3, for example, finally allows Get-ChildItem to specify “files only” or “directories only” (but their way of specifying attributes is a whole other syntax, which leads me to think it was specced…

0

PowerShell for Non-N00bs: Formatting Time With RegEx

So, last episode we learned how to format the output of a LastBootUpTime property from the WIN32_OperatingSystem WMI query to something human readable using WMI.  What if that didn’t exist?   PSH> (Get-WmiObject -Query ‘SELECT LastBootUpTime FROM Win32_OperatingSystem’).LastBootUpTime20090712112652.125000-420 So, we have this ugly string.  Hhow do we convert it to something we can use (namely, a string…

0