Solved

problem with a query wmi

Posted on 2013-05-29
9
296 Views
Last Modified: 2013-05-30
A txt file monitoring.env contains a list for exclude windows disk of monitoring

k:\\data\\sql\\:DISK:OFF
k:\\data1\\sql\\:DISK:OFF

With the folowing code, only the first line k:\\data\\sql\\:DISK:OFF is read :
$MONITORING = gci -Recurse ($CONF_INST_CONFIG) -in *.env
$EXCLUDE_DISK=get-content $MONITORING | where-object {$_.contains(":DISK:OFF")} |Foreach-Object {$_ -replace ":DISK:OFF", ""} -ErrorAction silentlycontinue
if ($EXCLUDE_DISK -ne $null) {
$LIST_EXCLUDE_DISK =  [string]::join('', $EXCLUDE_DISK) + ''
}
$LIST_DISK_1 = Get-WmiObject Win32_Volume -Filter "DriveType!='5' and not label like '%OS%'" |where-object {$_.name -notmatch $LIST_EXCLUDE_DISK}

How can I resolve this?

Thanks
0
Comment
Question by:bibi92
  • 5
  • 4
9 Comments
 
LVL 39

Expert Comment

by:footech
ID: 39206377
I think it's reading everything just fine.  It's what you're trying to do afterward that is having problems.
What are you trying to do with the line below?
$LIST_EXCLUDE_DISK =  [string]::join('', $EXCLUDE_DISK) + ''
That just gives you a result like "k:\\data\\sql\\k:\\data1\\sql\\".

And what are you trying to filter with the Where-Object in
$LIST_DISK_1 = Get-WmiObject Win32_Volume -Filter "DriveType!='5' and not label like '%OS%'" |where-object {$_.name -notmatch $LIST_EXCLUDE_DISK}  ?
0
 

Author Comment

by:bibi92
ID: 39206738
With list_exclude_disk Disks are separeted with space.
With where object, I try to build list_disk_1 without Disks in list_exclude_disk
Thanks
0
 
LVL 39

Expert Comment

by:footech
ID: 39207137
If you wanted them separated by a space you could do either of the following:
$LIST_EXCLUDE_DISK =  [string]::join(' ', $EXCLUDE_DISK)
$LIST_EXCLUDE_DISK =  $EXCLUDE_DISK -join " "

Open in new window

But I don't see what that gets you.  You don't have any volumes with the name "k:\\data\\sql\\ k:\\data1\\sql\\" do you?  Or even "k:\\data\\sql\\"?  I'm quite certain you're just looking to get the drive letter like "k:\".

If I'm correct you can use the following:
$MONITORING = gci -Recurse ($CONF_INST_CONFIG) -in *.env
$EXCLUDE_DISK = @(Select-String $MONITORING -pattern "^([A-Z]:\\).+:DISK:OFF" | ForEach-Object {$_.matches} | ForEach-Object {$_.groups[1].value} | Select -Unique)
$LIST_DISK_1 = Get-WmiObject Win32_Volume -Filter "DriveType!='5' and not label like '%OS%'" | Where-Object {$EXCLUDE_DISK -notcontains $_.name}

Open in new window

BTW, in my testing if you want to return drives that don't have a label you would have to adjust the WMI filter to include "label = NULL".
0
 

Author Comment

by:bibi92
ID: 39207842
For answer :
But I don't see what that gets you.  You don't have any volumes with the name "k:\\data\\sql\\ k:\\data1\\sql\\" do you?  Or even "k:\\data\\sql\\"?  I'm quite certain you're just looking to get the drive letter like "k:\".

--> I have the volumes k:\\data\\sql\\ k:\\data1\\sql\\ but I want to exclude them from $LIST_DISK_1.

I have tested the code.
The result from $EXCLUDE_DISK is k:\ and not k:\\data\\sql\\ k:\\data1\\sql\\.

Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 39

Assisted Solution

by:footech
footech earned 500 total points
ID: 39208278
OK, if you have the volumes "k:\\data\\sql\\" and "k:\\data1\\sql\\", the below will exclude them.  I just changed the matching pattern slightly.
$MONITORING = gci -Recurse ($CONF_INST_CONFIG) -in *.env
$EXCLUDE_DISK = @(Select-String $MONITORING -pattern "^([A-Z]:\\.+):DISK:OFF" | ForEach-Object {$_.matches} | ForEach-Object {$_.groups[1].value} | Select -Unique)
$LIST_DISK_1 = Get-WmiObject Win32_Volume -Filter "DriveType!='5' and not label like '%OS%'" | Where-Object {$EXCLUDE_DISK -notcontains $_.name}

Open in new window

0
 

Author Comment

by:bibi92
ID: 39208294
Sorry unless I'm mistaken I don't see any difference between the code in posted ID: 39208278 and the code in posted  ID: 39207137.

Thanks
0
 

Author Comment

by:bibi92
ID: 39208295
Sorry I'm tired, the difference is ([A-Z]:\\.+)
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 39208343
Correct.  If that works for you, it could even be simplified to "^(.+):DISK:OFF$".
0
 

Author Closing Comment

by:bibi92
ID: 39208592
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A procedure for exporting installed hotfix details of remote computers using powershell
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now