Solved

build a list disk to exclude of monitoring

Posted on 2013-05-29
4
281 Views
Last Modified: 2013-05-29
Hello

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) + ''
}
How can I modify it?

Thanks
0
Comment
Question by:bibi92
  • 3
4 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39204535
$MONITORING = gci -Recurse ($CONF_INST_CONFIG) -in *.env 
$EXCLUDE_DISK=$MONITORING | %{ gc $_ | where-object {$_.contains(":DISK:OFF")} 
|Foreach-Object {$_ -replace ":DISK:OFF", ""} -ErrorAction silentlycontinue
}
if ($EXCLUDE_DISK -ne $null) {
$LIST_EXCLUDE_DISK =  [string]::join('', $EXCLUDE_DISK) + ''
}

Open in new window


are you trying to change the txt file in the process?
what's the -replace used for?
0
 

Author Comment

by:bibi92
ID: 39204825
No I'm not trying to change the txt file in the process.
The replace is used before executing
$LIST_DISK_1 = Get-WmiObject Win32_Volume -Filter "DriveType!='5' and not label like '%OS%'" |where-object {$_.name -notmatch $LIST_EXCLUDE_DISK}
I try your code but the result is the same.
0
 

Author Comment

by:bibi92
ID: 39205087
where-object {$_.name -notmatch $LIST_EXCLUDE_DISK} does not work because
"k:\\data\\sql\\ k:\\data1\\sql\\"

How can I resolve it?
0
 

Author Closing Comment

by:bibi92
ID: 39206174
Thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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 …
A brief introduction to what I consider to be the best editor for PowerShell.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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