Advertisement
Cogger

Test_IEX_Get-Joke.ps1

Nov 11th, 2022 (edited)
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     $DadJoke = Invoke-WebRequest -Uri "https://icanhazdadjoke.com" -Headers @{accept="application/json"} | Select -ExpandProperty Content | ConvertFrom-Json | Select -ExpandProperty Joke
  2.  
  3. $error.clear()
  4. try { $QuestionExists = "$DadJoke" -Match "?" }
  5. catch { "Error occured" }
  6. if (!$error) { $CharArray =$DadJoke.Split("?") }
  7.  
  8.  
  9. $TwoPeriodsExists = ($DadJoke.ToCharArray() -eq '.').count
  10. $error.clear()
  11. try { $TwoPeriodsExists -eq 2 }
  12. catch { "Error occured" }
  13. if (!$error) { $CharArray =$DadJoke.Split(".") }
  14.  
  15.  
  16. If ($CharArray.count -eq 2) {
  17.   (New-Object -com SAPI.SpVoice).speak($CharArray[0])
  18.  
  19.   }  Else {
  20.  
  21.   (New-Object -com SAPI.SpVoice).speak($CharArray[0]) ; Start-Sleep -s 2
  22.   (New-Object -com SAPI.SpVoice).speak($CharArray[1])
  23. }
  24.  
  25.  
  26.  
  27. $UN = (Get-LoggedInUser -ComputerName $env:COMPUTERNAME).UserName
  28.  
  29. Write-Host(" Run by $UN ")  -ForegroundColor Yellow
  30. Write-Host("Test Succeeded! Joke told! ")  -ForegroundColor Yellow
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement