Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem with a query wmi

Posted on 2013-05-29
9
Medium Priority
?
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 41

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 41

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 41

Assisted Solution

by:footech
footech earned 2000 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 41

Accepted Solution

by:
footech earned 2000 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

Protect Your Retail Business and Reputatio

Wi-Fi access doesn't just impact your business & customer experience, it can also affect your security.  Join us for a webinar on Sept. 28th to learn more about the top threats and trends impacting retail today, and the key solutions to protecting retail networks and reputations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonstā€¦
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

660 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