Public/Request-WebPage.ps1
Function Request-WebPage { <# .Synopsis Automatically refresh a website .Description Refreshes a given website automatically, this is very usefull for a machine in kiosk mode as it allows you to automatically refresh the displayed page on an interval. This function only works when useing Internet Explorer to display the website. .Parameter interval Sets the refresh interval in seconds, default is 300 seconds (5 minutes) .Parameter URL The URL that you want to automatically refresh .Example Request-WebPage -interval 300 -URL http://www.microsoft.com Refreshes microft.com every 300 seconds .Inputs System.Int32 System.String .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding()] [OutputType('None')] Param( [Parameter()] [int]$Interval = 300, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [ValidatePattern('^(?!mailto:)(http(s)?|ftp)://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?')] [Alias('Website')] [string]$URL ) Begin { If (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } If (-not $PSBoundParameters.ContainsKey('ErrorAction')) { $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference') } } Process { Write-Output "Refreshing Internet Explorer Windows every $interval seconds. Press any key to stop." $shell = New-Object -ComObject Shell.Application Do { Write-Verbose ("{0}:: Refreshing {1}" -f $MyInvocation.MyCommand, $URL) $shell.Windows() | Where-Object { $_.Document.url -like $URL } | ForEach-Object { $_.Refresh() } Start-Sleep -Seconds $interval } Until ([System.Console]::KeyAvailable) [System.Console]::ReadKey($true) | Out-Null } End { } } |