UNSOLVED

DELL-Bill Gr

updated

15 years ago

0

18997

November 21st, 2011 11:00

Powershell - Wildcard?

This post has been copied from the former Compellent User Forum and placed here for your reference.  This code is made available AS IS, without warranty of any kind.  The entire risk of the use or the results from the use of this code remains with the user.

Wildcard? – Originally posted By CAH, 13 Mar 2011

CAH - I'm having trouble using a wildcard character (*) with the Get-SCVolume command.  I use Powershell quite often to manage Exchange 2010, but this is the first time I've tried connecting to Compellent.  I can pull up exact volume names just fine, but haven't had any luck using a wildcard in my search.  I'm just trying to search for volumes with the word "Exchange" in their name.  Shouldn't something like this work for that purpose?

Get-SCVolume *Exchange*

or

Get-SCVolume -Name *Exchange*

or

Get-SCVolume | Where ($_.Name -like "Exchange")

I'm not getting any errors with these, but I'm not getting any results with them either.  Could someone steer me in the right direction?

Thanks,

Chris

ThomVis - I would:

# Read all volumes from CSC

$Volumes=Get-SCVolume

#Run through the list of all volumes

$Volumes | foreach {

    # Do your string selection on $_.Name

CAH - Thanks for the reply.  That's a great idea to just set a volume variable up front to simplify the rest of the script.  I also did some more playing with my syntax, and this gives me the results I was trying to get the other night:

get-scvolume | where {$_.name -like "*exchange*"}

So I think I'll end up doing something like this:

#get all Exchange volumes

$ExchangeVolumes=get-scvolume | where {$_.name -like "*exchange*"}

#Run a foreach for manipulating those volumes

$exchangevolumes | foreach {

#Exchange script

}

Thanks again for helping me think this through.

Chris

kalord - In this situation, the conditional operator you are looking for would be -match and not -like. 

-match is powerful in that it uses regular expressions for pattern matching

Example:

# This will return any string which contains the term 'exchange'

Get-SCvolume | where {$_.Name -match "exchange"}

  CAH - You're right, the match operator works great for this purpose.  Thanks for your reply.

Chris

No Responses