Author Posts

January 1, 2012 at 12:00 am

by AevnsGrandpa at 2013-04-01 12:50:47

I have looked around the WMI spaces for hard drive info that I know of, diskdrive and volume, and am not finding a property that would tell me if the drive is failing or failed.

Just had a server have one of 2 drives set up in a RAID0 fail and really would have like to known it ahead of time if at all possible. I would work this into a script doing a invoke-command while I am in a pssession on the server from my laptop.

Thanks for the help!

Jeff

by coderaven at 2013-04-01 14:10:25

Look at Win32_LogicalDisk and Win32_DiskDrive property availability and ConfigMgrErrorCode. They tell the status for you.

by AevnsGrandpa at 2013-04-01 14:13:23

I guess I answered part of my own question. I am grabbing the system log and looking at just entries for the HP Drive Array. this brings a question of how do I limit the length of the fields I bring back? The message field for some of these entries is huge!! I would like to limit it to say 100 characters. Would I use something like;

Select-object @{Expression={xxxxxx)}; label="xxxxxx"}

And get the message field then as a string and somehow truncate it at 100 characters?

Jeff

by coderaven at 2013-04-02 06:07:26

Use the substring(0, 100) to get the first 100 chars

by MasterOfTheHat at 2013-04-02 06:34:01

Take a look at the Win32_DiskDriveStatus property, too. I'm not sure if it is accurate for all disk types/makes...

by AevnsGrandpa at 2013-04-03 06:22:42

Thanks, I will try that out.

Jeff

by AevnsGrandpa at 2013-04-03 07:11:59

Ok, in playing with this I am able to use the substring to shorten an element of an array;

$a = get-eventlog system -newest 10 | select Source,Message,TimeGenerated
foreach ($message in $a) {$short = $message.Message.substring(0,10)}

So I can gererate a separate string with the Message part of the event log shortened to a certain amount of characters. However in doing this it looks like I have to totally tear apart end array element into 3 strings and then put them back together to just have a shortened message.

$wholething = $a[0].Source + $short[0] + $a[0].TimeGenerated

Is there a better way of going this?

Jeff

by ArtB0514 at 2013-04-03 07:25:11

$a = Get-EventLog System -Newest 10 | Select @{Name='Wholething';Expression={"{0} {1} {2}" -f $_.Source, $_.Message.Substring(0,10),$_.TimeGenerated}}
$a.Wholething

by MasterOfTheHat at 2013-04-03 07:25:32

Try it like this:
Get-EventLog system -Newest 10 | Select-Object Source, @{label="Shortened Message";expression={$_.Message.substring(0,10)}}, TimeGenerated

Source Shortened Message TimeGenerated
------ ----------------- -------------
Service Control Manager The Multim 4/3/2013 9:21:14 AM
Service Control Manager The WinHTT 4/3/2013 9:15:22 AM
Service Control Manager The Office 4/3/2013 9:15:19 AM
Service Control Manager The Multim 4/3/2013 9:15:00 AM
Service Control Manager The WinHTT 4/3/2013 9:12:45 AM
Service Control Manager The Multim 4/3/2013 9:02:23 AM
Service Control Manager The WinHTT 4/3/2013 8:54:45 AM
Service Control Manager The Multim 4/3/2013 8:54:30 AM
Service Control Manager The Multim 4/3/2013 8:51:47 AM
Service Control Manager The Multim 4/3/2013 8:46:45 AM

EDIT: whoops! Looks like Art just barely beat me to it. Since they're a little different, I'll leave my post out here...

by AevnsGrandpa at 2013-04-03 08:19:42

Thanks, I had wondered and asked in an eariler post if I needed to d the whole @{label...;expression} thing.

Jeff

by AevnsGrandpa at 2013-04-03 08:23:14

Oh and one last (dumb) question. What does "@" mean?

Jeff

by MasterOfTheHat at 2013-04-03 08:33:17

The @{} syntax denotes a hash table. You're using a hash table in that Select-Object cmdlet to create a calculated property. Very handy for making the output human readable, concatenating properties, combining properties arithmetically to create a new property, etc.