-1

I have written a script in PowerShell which creates aws ebs snapshot , its working fine without an issue , except i am not able get the Progress status at regular interval to proceed with next step in script. Until unless i dont get update that snapshot is 100% completed i cannot proceed with next step in my script which is upgrade of application. Any help is appreciated.

    Import-Module -name AWSPowerShell
    $CostIdValue = Read-Host "Please provide ID , e.g.:- 111"
    $CostId = Get-EC2Volume -profilename xyz -region us-east-2 | ? { $_.Tags.Count -gt 0 -and $_.Tags.Key -eq "CostId" -and $_.Tags.Value -eq $CostIdValue} | Select-Object -ExpandProperty VolumeId 
    $snapshot = New-EC2Snapshot -profilename xyz -region us-east-2 -VolumeId $CostId
    #$snapshotId = Get-EC2Volume -profilename xyz -region us-east-2 | ? { $_.Tags.Count -gt 0 -and $_.Tags.Key -eq "CostId" -and $_.Tags.Value -eq $CostIdValue} | Select-Object -ExpandProperty SnapshotId
    $a = $snapshot.SnapshotId
    #Write-Output $a
    New-EC2Tag -profilename xyz -region us-east-2 -Resource $a -Tag @{ Key="CostId"; Value = $CostIdValue }
    
    $i = Get-EC2Snapshot -profilename xyz -region us-east-2 | ? { $_.Tags.Count -gt 0 -and $_.Tags.Key -eq "CostId" -and $_.Tags.Value -eq "$CostIdValue"} | Select-Object -ExpandProperty State

for ($i = 1; $i -le 100; $i++ )
{
Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i;
}
Abhishek
  • 121
  • 5
  • [1] for you to get progress on something ... you need to be INSIDE that process [inside a loop, for instance]. your progress display is OUTSIDE the process. [*grin*] ///// [2] the progress cmdlet is SLOW ... so you will slow down your script somewhat if you use it. ///// [3] there does not seem to be anything in the snapshot process to monitor for showing progress. what can you use to show that something is happening? – Lee_Dailey Apr 16 '21 at 13:42
  • Thanks.. I am looking to take the progress percentage , like it ping the snapshot kind of logic using get and print the status , as this script. will become part of application upgrade and application upgrade will only happen after snapshot becomes 100%.. – Abhishek Apr 16 '21 at 14:36
  • in order to show progress ... you need to _detect it_. is there anything in the process that lets you know how much of the process has completed? i can't see any such thing when i read thru the docs. – Lee_Dailey Apr 16 '21 at 15:09
  • As far as i know we dont have anything specific for that , so now i am thinking to create wait condition in script which will check every 5 mins and write the output which again is not standard way. – Abhishek Apr 16 '21 at 15:25
  • start the snapshot call in a PSJob and then call to it every few seconds from your main script. that can at least let you show a "something is still happening" message. – Lee_Dailey Apr 17 '21 at 00:47

1 Answers1

0

So i used while and checked the status on continuous interval. Now script is checking the snapshot based upon status and its. working perfectly as expected. Thanks everyone for jumping in..

while ((Get-EC2Snapshot -profilename xyz -region $region | ? { $_.Tags.Count -gt 0 -and $_.Tags.Key -eq "CostId" -and $_.Tags.Value -eq "$CostIdValue"}).Status -ne "completed")
 {
       "Snapshot for db is $CostIdValue pending ..."
        Start-Sleep -Seconds 5
    }
    
      "Snapshot for db is $CostIdValue completed ..."
Abhishek
  • 121
  • 5