Advertisement
Raimonds

msg_yesno

Mar 18th, 2016
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Default params if no input given.
  2. param (
  3.     [string]$txtFileName="default",
  4.     [int]$duration=0,
  5.     [string]$title="CompanyName IT"
  6. )
  7. #Path to message repo
  8. $msgPath = ("\\namespace\it\deploy\_messages\" + $txtFileName + ".txt")
  9.  
  10. #exit early if txt file doesn't exist
  11. If (-Not (Test-Path $msgPath)) {
  12.     exit 1
  13. }
  14.  
  15. #Get full name and surname of current user
  16. #Might require .NET 4.6.1 or PS 4.0 to work
  17. Add-Type -AssemblyName System.DirectoryServices.AccountManagement;
  18. $user = [System.DirectoryServices.AccountManagement.UserPrincipal]::Current.DisplayName;
  19.  
  20. #Combine header "Dear $username" and txt file contents
  21. $msg = Get-Content -Path $msgPath | Out-String
  22. $msgFinal = "Dear " + $user + "`n`n" + $msg
  23.  
  24. $a = new-object -comobject wscript.shell
  25. $intAnswer = $a.popup($msgFinal,$duration,$title,4+32+4096)
  26.  
  27. #If user presses NO or Time runs out package fails. Replace comment to succeed when time runs out.
  28. #If (($intAnswer -eq 6) -or ($intAnswer -eq -1)) {
  29. If ($intAnswer -eq 6) {
  30.     exit 0
  31. } else {
  32.     exit 69
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement