A N

October 5, 2015

Delay a certain minute (countdown) with Powershell Write-Progress

Filed under: Tips — donrsh @ 12:24 pm
<#	
	.NOTES
	===========================================================================
	 Created on:   	2015-09-09 
	 Created by:   	Arash Nabi
	 Email: 	    arash@nabi.nu 

	===========================================================================
	.DESCRIPTION 
		The function creates a write-progress bar with coundown. Usefull in script
		when you want to paus a certain minut(s)
	.Exampel
		Delay-Time -Min 10
	
#>
function Delay-Time
{
	[CmdletBinding()]
	[OutputType([int])]
	Param
	(
		
		[Parameter(Mandatory = $true,
				   ValueFromPipelineByPropertyName = $true,
				   Position = 0)]
		[int]$Min
	)
	$D = get-date
	$x = $min * 60
	$length = $x / 100
	while ($x -gt 0)
	{
		$f = $d.AddMinutes(1)
		$min = [int](([string]($x/60)).split('.')[0])
		$text = " " + $min + " minutes " + ($x % 60) + " seconds left"
		Write-Progress "Please wait until $f" -status $text -perc ($x/$length) -Verbose
		start-sleep -s 1
		$x--
		Write-Progress -Activity Done! -Completed -Verbose
	}
	
}
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: