View history of start and end execution times in Powershell
Recently I've been trying to scale my Azure SQL database up from a low pricing tier to a higher pricing tier. It seems like the process can take between minutes to hours.
I wanted a way of measure how long this would take and while using the Measure-Command
commandlet was useful in showing the duration, it didn't show the time it was executed from start to finish. While the duration was helpful, it didn't really reflect the true amount of time it took to scale because when I logged onto the Azure Portal, it would still say "Scaling database from S1 to S7" even after the 8mins of execution between start and end.
So to measure the true duration of the scaling operation, I had to stroll through the Activity Log and check for the "Succeeded" time against my local powershell sessions' execution start time. But how? By default, Powershell doesn't show the time of the execution in the command prompt but we have a handy commandlet display this information for us.
Get-History | Format-List
Which will give us
Id : 12
CommandLine : Measure-Command {
# Scale the database performance to Standard S1
$database = Set-AzureRmSqlDatabase -ResourceGroupName $secondaryresourcegroupname `
-ServerName $secondaryservername `
-DatabaseName $databasename `
-Edition "Standard" `
-RequestedServiceObjectiveName "S1"
}
ExecutionStatus : Completed
StartExecutionTime : 3/01/2018 9:53:33 AM
EndExecutionTime : 3/01/2018 9:56:08 AM
Id : 13
CommandLine : Measure-Command {
# Scale the database performance to Standard S7
$database = Set-AzureRmSqlDatabase -ResourceGroupName $secondaryresourcegroupname `
-ServerName $secondaryservername `
-DatabaseName $databasename `
-Edition "Standard" `
-RequestedServiceObjectiveName "S7"
}
ExecutionStatus : Completed
StartExecutionTime : 3/01/2018 10:19:51 AM
EndExecutionTime : 3/01/2018 10:19:55 AM
Id : 14
CommandLine : Measure-Command {
# Scale the database performance to Standard S7
$database = Set-AzureRmSqlDatabase -ResourceGroupName $secondaryresourcegroupname `
-ServerName $secondaryservername `
-DatabaseName $databasename `
-Edition "Standard" `
-RequestedServiceObjectiveName "S7"
}
ExecutionStatus : Completed
StartExecutionTime : 3/01/2018 10:20:10 AM
EndExecutionTime : 3/01/2018 10:28:43 AM