Thursday, January 30, 2014

How to use PowerShell console window title to monitor SharePoint 2013 upgrade status and timing?



PowerShell script is heavily used for SharePoint 2013 upgrade and also daily administration. We have automated almost all SharePoint 2013 upgrade activities using PowerShell. Developers normally write the SharePoint 2013 upgrade step status and timing into log file so we could tracking the progress and time spend. It would be helpful to provide feedback or status messages directly  to the PowerShell so person running the script could know what the script is doing.

There are a number of ways you can accomplish this such as using Write-Host, Write-Progress or Write-Verbose. The easy way is to use the title bar of the PowerShell console or ISE. Here is example to display the time spend on one of the SharePoint PowerShell command “Get-Get-SPSite -limit ALL”.

# Get current time
$startTime = [DateTime]::Now

# Execute any PowerShell script
Get-SPSite -limit ALL

# Calculate time spend
$totalTime = [DateTime]::Now - $startTime

# Set time spend in second as window title & display
$status = "Get-Get-SPSite -limit ALL spend " + $totalTime.TotalSeconds + " seconds"
$host.ui.RawUI.WindowTitle = $status


The result is displayed as in the following screen shot as Window title.


As best practice, you might need to store the default original window title in a variable and set back after your activities completed. You could use the following PowerShell scripts.

# Store original window title
$title = $host.ui.RawUI.WindowTitle

# Do something here

# Set back original window title
$host.ui.RawUI.WindowTitle = $title

Now, you should have the  PowerShell console directly display the upgrade status and timing for you in SharePoint 2013 upgrade.

No comments:

Post a Comment