Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $DadJoke = Invoke-WebRequest -Uri "https://icanhazdadjoke.com" -Headers @{accept="application/json"} | Select -ExpandProperty Content | ConvertFrom-Json | Select -ExpandProperty Joke
- $error.clear()
- try { $QuestionExists = "$DadJoke" -Match "?" }
- catch { "Error occured" }
- if (!$error) { $CharArray =$DadJoke.Split("?") }
- $TwoPeriodsExists = ($DadJoke.ToCharArray() -eq '.').count
- $error.clear()
- try { $TwoPeriodsExists -eq 2 }
- catch { "Error occured" }
- if (!$error) { $CharArray =$DadJoke.Split(".") }
- If ($CharArray.count -eq 2) {
- (New-Object -com SAPI.SpVoice).speak($CharArray[0])
- } Else {
- (New-Object -com SAPI.SpVoice).speak($CharArray[0]) ; Start-Sleep -s 2
- (New-Object -com SAPI.SpVoice).speak($CharArray[1])
- }
- $UN = (Get-LoggedInUser -ComputerName $env:COMPUTERNAME).UserName
- Write-Host(" Run by $UN ") -ForegroundColor Yellow
- Write-Host("Test Succeeded! Joke told! ") -ForegroundColor Yellow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement