Solved

problem with a query wmi

Posted on 2013-05-29
9
313 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Populate department based on OU - Powershell 2 24
Exchange 2010 internal URLs 2 40
Import ProxyAddress and other fields 13 49
Exchange powershell help 2 29
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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