View Only
  • 1.  Get-View -Filter HashTable expression Help

    Posted Jul 17, 2015 04:56 PM

    Need help with using get-view's -filter hashtable.    I have a script that I am using get-view to get clusters, I am providing a method to limit the results to a specific cluster in the event the person running the script only needs to run it against a single cluster.   My problem is when we have two clusters who's name are almost the same (the first part is identical then a space and more text) the filter will return both clusters..  I believe you can use a regex express with the -filter hastable but I am not exactly sure how to do that or how to build that expression.    Below is an example of the script and example of the clusters names.

    Clusters in Environment:


    NLX-TST-001 (BETA)




    Key parts of script related to my issue.

    $viserver = "nlxtxtvc01"

    $clustername = "NLS-TST-001"

    $ClusterFilter = @{"name"=$clustername}

    $clustersview = get-view -viewtype clustercomputeresource -server $viserver -filter $clustername

    When I run the get-view as listed above the $clustersview will contain 2 results:


    NLX-TST-001 (BETA)

    When what I want it to only return NLX-TST-001.      Now I know I could test to see if $clustersview contains more than 1 result and then using a loop or other matching mechanism filter to only the one I want.  But I believe since the -filter will allow you to use regex this should be able to be done right?   Possibly having to have two criteria in the regex express using to match the name...... Unfortunately I am not that experience with using or building regex expressions and I have mostly used very simple -Filters in the past..

    Any Help will be greatly appreciated.






  • 2.  RE: Get-View -Filter HashTable expression Help
    Best Answer

    Posted Jul 17, 2015 05:10 PM

    Change the RegEx to this

    $clustername = "NLS-TST-001$"

    The dollar sign tells RegEx that the match has to end with characters you specified, it's an end-of-line in a way

  • 3.  RE: Get-View -Filter HashTable expression Help

    Posted Jul 17, 2015 05:55 PM

    Thanks!  That did it.. and just had to make a small modification since the $clustername variable is actually populated by user input I just did a $clustername = $clustername+"$"