Analysis that reads a file from diskpart command

I am using the diskpart command to give status of each drive and if its online or offline. The below is the output from the following command

waithidden cmd.exe /c diskpart /s diskpart.txt > c:\logfile.txt

i need to parse the output below for only the disk(s) and status

Disk 0 Online

file
Microsoft DiskPart version 10.0.19041.964

Copyright © Microsoft Corporation.
On computer: ADMINIB-7N4T179

Disk ### Status Size Free Dyn Gpt


Disk 0 Online 447 GB 505 MB
Disk 1 Online 232 GB 0 B
Disk 2 Online 931 GB 0 B
Disk 3 No Media 0 B 0 B

I like a regex for this one.

q: (matches (case insensitive regex "^(disk)\s(\d+)\s(\w+)\s") of it) of lines whose (it starts with "Disk" and it does not contain "Status") of file "c:\logfile.txt"

slight improvement to also capture “No Media” Status type

q: (concatenation " " of parenthesized parts (1;2;3) of it) of (matches (case insensitive regex "^(disk)\s(\d+)\s(\w+|\w+\s\w+)\s(\d+)") of it) of lines whose (it starts with "Disk" and it does not contain "Status") of file "c:\logfile.txt" 
A: Disk 0 Online
A: Disk 1 Online
A: Disk 2 Online
A: Disk 3 No Media
2 Likes

I can’t Brolly how much i appreciate this. I tested in Q&A debugger and i am showing the snapshot to you. The file exists , the file is in the correct location (i renamed the file in your relevance and then renamed the file on the drive to match) So i am adding a snapshot as there is no display of data The Q&A is not showing error but displays no data and 0 evaluation time. it is set to evaluate to client.

I tried your first example and its the same issue as it is not displaying data just time to evaluate which is zero.

By the way i renamed the file back to logfile.txt so that it matched your relevance.

I believe the regex may not match the spaces that come at the front of the line…should have something shortly.

I tweaked the regex slightly to account for more than one space character between the fields

q: lines whose (it as trimmed string starts with "Disk" and it does not contain "Status") of file "c:\logfile.txt" 
A:   Disk 0    Online          400 GB  1024 KB        *
A:   Disk 1    No Media        400 GB  1024 KB        *
T: 2.433 ms
I: plural file line

q: (concatenation " " of parenthesized parts (1;2;3) of it) of (matches (case insensitive regex "^\s*(disk)\s(\d+)\s+(\w+|\w+\s\w+)\s*(\d+)") of it) of lines whose (it as trimmed string starts with "Disk" and it does not contain "Status") of file "c:\logfile.txt" 
A: Disk 0 Online
A: Disk 1 No Media
T: 1.881 ms
I: plural string

(edit: the difference in spacing is probably an artifact of copy/pasting the example from the Forum. In HTML, two spaces together are collapsed into one.)

1 Like

That fixed the problem Jason. Much appreciated. As always just picking your minds. How could you take what you have written and within an analysis add the property but instead of the list display you get. you change it to show property one = status of disk 0 and you add property 2 and show disk 1 status , etc until you end of disks. So it property would only show the first disk and it does not contain Status , but stops there. then the 2nd property would skip the first disk and not status but pick the 2nd Disk and not status . you would have it read each disk only . Hope that makes since . So when looking at the results you would see the disk in each column.

1 Like

Ahhh Nice find Jason Since I did not have the original file, it looks like the forum pasted version was missing those leading spaces.

Thanks Brolly for putting that together for me.

Jason or Brolly any thoughts on how to take your work and modify to do this

As always just picking your minds. How could you take what you have written and within an analysis add the property but instead of the list display you get. you change it to show property one = status of disk 0 and you add property 2 and show disk 1 status , etc until you end of disks. So it property would only show the first disk and it does not contain Status , but stops there. then the 2nd property would skip the first disk and not status but pick the 2nd Disk and not status . you would have it read each disk only . Hope that makes since . So when looking at the results you would see the disk in each column.

Could be done with adding a filter for “disk 1” and another filter for “disk 2”.
I rather like having them all in a single property instead of trying to break them out into an arbitrary number of mini properties. What about that one server that has 82 disks?

It might be of value for disk 0 1 and 2 only, and use the generic for the rest?

Brolly. After reviewing your answer and thinking it through, i am fine with the way it is now, Thank you for all your help as well as Jason.

1 Like