-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
MOTD.ps1
22 lines (20 loc) · 973 Bytes
/
MOTD.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Retrieve quote from goldenquotes.net
#Get random numbers for the page number and quote number
$randompage = Get-Random -Minimum 1 -Maximum 7
$randomquote = Get-Random -Minimum 1 -Maximum 100
#Check if the module PSParseHTML is installed and install
#the module if it's not installed
if (-not (Get-Command ConvertFrom-HTMLClass -ErrorAction SilentlyContinue)) {
Install-Module PSParseHTML -SkipPublisherCheck -Force:$true -Confirm:$false
}
#Get a random quote and display it
try {
$page = Invoke-RestMethod -Uri "https://www.thegoldenquotes.net/best-100-public-domain-quotes-of-all-time-collection-0$($randompage)/"
$convertedpage = ConvertFrom-HTMLClass -Class "siteorigin-widget-tinymce" -Content $page -ErrorAction SilentlyContinue
$quote = "Message Of The Day:`n" + $($convertedpage)[$($randomquote)].substring(2)
return $quote
}
#Show an error is there is an issue
catch {
Write-Warning ("Error retrieving MOTD, please try again later...")
}