UNSOLVED

DELL-Bill Gr

updated

15 years ago

0

4759

November 21st, 2011 11:00

Powershell - Volume Search script

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.

Volume Search script – Originally posted By bmiddaugh, 18 Jul 2011

bmiddaugh - I took the script from here: http://braunblog.com/2010/03/03/search-your-compellent-storage-center-using-windows-powershell/

 and made some changes to search for volumes. This script will search for a key word in a volume name and give you:

VolumeIndex VolumeName          LogicalPath         Mappings

----------- ----------          -----------         --------

 

If you run the script and use *keyword* the script will search for that keyword in your volume names.

PS C:\scripts> .\findvolumeindex.ps1

Enter the volume you want to search for (wildcards OK): *view*

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# This sample script is provided "as is" with no warranty whatsoever;

# you assume all responsibilty of the consequences of use.

####################################################################################

#This script will search for a key word in a volume name and give you:

#

#        VolumeIndex VolumeName          LogicalPath         Mappings

#        ----------- ----------          -----------         --------

#

####################################################################################

$scname = Read-Host "What Storage Center do you want to search? (IP or hostname)"

$scusername = Read-Host "What is the username for your account on this Storage Center?"

$scpassword = Read-Host -AsSecureString -Prompt "What is the password?"

$ErrorActionPreference = "SilentlyContinue"

$compSnapinName = "Compellent.StorageCenter.PSSnapin"

$searchterm = Read-Host "Enter the volume you want to search for (wildcards OK)"

 

# ****** FUNCTIONS USED IN THE MAIN SCRIPT ********

# Check that the snapin is loaded

function CheckForSnapin

{

    param([string]$snapinName)

    $SnapinLoaded = $FALSE

    $currentSnapins = $null

    $currentSnapins = Get-PSSnapin

    foreach ($snapin in $currentSnapins)

    {

        if ($snapin.Name -eq $snapinName)

        {

            $SnapinLoaded = $TRUE

        }

    }

    $SnapinLoaded

}

# ****** MAIN SCRIPT STARTS HERE ********

# Check for Snapin and load if needed

$snapinLoaded = CheckForSnapin -snapinName $compSnapinName

if ($snapinLoaded -eq $FALSE)

{

    Add-PSSnapIn $compSnapinName

    $snapinLoaded = CheckForSnapin -snapinName $compSnapinName

    if ($snapinLoaded -eq $FALSE)

    {

        Write-Host "Unable to load the Compellent PowerShell Snapin - exiting" -Fore Red

        break;

    }

}

# Connect to the Compellent controller

$connected = Get-SCConnection -HostName $schost -User $scuser -Password $scpass -Default

if ($connected.Host -ne $schost)

{

    Write-Host "Unable to connect to the Compellent controller $schost as user $scuser - exiting" -Fore Red

    break;

}

# Valid parameter found - start script

# Instantiate connection

Write-Host "`nOpening connection...";

try

{

       $conn = Get-SCConnection -HostName $scname -User $scusername -Password $scpassword;

}

catch

{

       Write-Host "Error: " $_;

       Break;

}

Write-Host "Connection established to $scname...";

# What are we searching for?

              # Find a volume

              $vols = Get-SCVolume -Connection $conn | where { $_.Name -like $searchterm }

              if($vols -ne $null)

              {

                     # Found some objects that might match

                     Write-Host "`nThe following volumes might match your query:"

                     foreach($vol in $vols)

                     {

                           # Create an output object for table formatting

                           $obj = new-Object PSObject;

                           # Add member properties with their name and value pair

               $obj | Add-Member NoteProperty VolumeIndex($vol.Index);

                           $obj | Add-Member NoteProperty VolumeName($vol.Name);

                           $obj | Add-Member NoteProperty LogicalPath($vol.LogicalPath);

                           #Get Mappings to volume

                           $mappings = Get-SCVolumeMap -VolumeIndex $vol.Index -Connection $conn

                           if($mappings -ne $null)

                           {

                                  $maps = ""

                                  foreach($mapping in $mappings)

                                  {

                                         $maps += $mapping.ServerName + " "

                                  }

                                  $obj | Add-Member NoteProperty Mappings($maps);

                           }

                           else

                           {

                                  # No mappings found

                                  $obj | Add-Member NoteProperty Mappings("None");

                           }

                           # Write the output to the screen

                           Write-Output $obj;

                     }

              }

              else

              {

                     # No objects found

                     Write-Host "`nSorry, no objects were found that match your query."

              }