UNSOLVED

DELL-Bill Gr

updated

15 years ago

0

15003

November 21st, 2011 11:00

Powershell - View that are using expired replays

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.

View that are using expired replays – Originally posted By pongowongo, 28 Jan 2011

pongowongo - I had a need to get a list of all the Volumes that had been created from a replay that has now expired. Having almost a hundred volumes on the SAN, I did not look forward to using the GUI to look at every volumes' replays to see which ones had expired and still existed due to a volume being created from them. So, I set out and created the PowerShell script below. This script will enumerate every volume that you have permissions to see and pull the replays for that volume and see if it was created from a replay that has now expired. Feel free to use in your environment and/or adapt it's use.

# Set the variables that are needed for the script to run

$ErrorActionPreference = "SilentlyContinue"

$compSnapinName = "Compellent.StorageCenter.Scripting"

$schost = Read-Host -Prompt "Please enter hostname or IP of the controller"

$scuser = Read-Host -Prompt "Please enter your username"

$scpass = Read-Host -AsSecureString -Prompt "Please enter your password"

# ****** 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;

}

Write-Host "Getting Volumes that are using expired replays"

$now = Get-Date

$activeReplays = Get-SCReplay | where {$_.State -eq "Active"}

if ($activeReplays -ne $null -or $activeReplays.Length -gt 0)

{

    foreach($activeReplay in $activeReplays)

    {

        $indexSplit = $activeReplay.Index.Split("-")

        if($activeReplay.SourceVolumeIndex -ne $indexSplit[0])

        {

            $createTime = [datetime]$activeReplay.CreateTime

            $sourceReplays = Get-SCreplay -SourceVolumeIndex $indexSplit[0] | where {$_.State -eq "Frozen" -and [datetime]$_.CreateTime -lt $createTime}

            if($sourceReplays -ne $null -or $sourceReplay.Count -gt 0)

            {

                $sourceReplay = $null

                if($sourceReplays.Length -gt 1)

                {

                    $sourceReplay = $sourceReplays[-1]

                }

                else

                {

                    $sourceReplay = $sourceReplays

                }

                if($sourceReplay.State -eq "Frozen" -and [datetime]$sourceReplay.ExpireTime -lt $now)

                {

                    Write-Host "Volume:" $activeReplay.SourceVolumeName "is using an expired replay" -Fore Red

                }

            }

            else

            {

                Write-Host "Volume:" $activeReplay.SourceVolumeName "- Unable to retrieve replay information" -Fore Red

            }

        }

    }

}

Write-Host "Finished"

 

Regards,

Hugh McDaid

bmiddaugh - Thank you Hugh. I like the script you posted very much. I did make some changes to the script. I changed the foreground color of the 2 outputs so they were not the same, and I show both the replay index and the volume index numbers. This way I can find the volumes and expire the replays.

 

# ****** 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;

}

Write-Host "Getting Volumes that are using expired replays"

$now = Get-Date

$activeReplays = Get-SCReplay | where {$_.State -eq "Active"}

if ($activeReplays -ne $null -or $activeReplays.Length -gt 0)

{

    foreach($activeReplay in $activeReplays)

    {

        $indexSplit = $activeReplay.Index.Split("-")

        if($activeReplay.SourceVolumeIndex -ne $indexSplit[0])

        {

            $createTime = [datetime]$activeReplay.CreateTime

            $sourceReplays = Get-SCreplay -SourceVolumeIndex $indexSplit[0] | where {$_.State -eq "Frozen" -and [datetime]$_.CreateTime -lt $createTime}

            if($sourceReplays -ne $null -or $sourceReplay.Count -gt 0)

            {

                $sourceReplay = $null

                if($sourceReplays.Length -gt 1)

                {

                    $sourceReplay = $sourceReplays[-1]

                }

                else

                {

                    $sourceReplay = $sourceReplays

                }

                if($sourceReplay.State -eq "Frozen" -and [datetime]$sourceReplay.ExpireTime -lt $now)

                {

                    Write-Host "VolIndex:"$activeReplay.SourceVolumeIndex "ReplayIndex:"$activeReplay.Index "VolName:" $activeReplay.SourceVolumeName "is using an expired replay" -Fore Yellow

                }

            }

            else

            {

                Write-Host "VolIndex:"$activeReplay.SourceVolumeIndex "ReplayIndex:"$activeReplay.Index "VolName:" $activeReplay.SourceVolumeName "- Unable to retrieve replay information" -Fore Red

            }

        }

    }

}

Write-Host "Finished"