Guest User

Untitled

a guest
Feb 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function waitForUserInput([parameter(mandatory=$true)][int]$TimeoutSeconds, [string]$Prompt){
  2. $counter = 0
  3. while($counter++ -lt $TimeoutSeconds){
  4. if(-not [console]::KeyAvailable){
  5. Start-Sleep -Seconds 1
  6. } else {
  7. $input = Read-Host -Prompt "$Prompt"
  8. break
  9. }
  10. }
  11. if($input){
  12. Write-Output "$input"
  13. }
  14. }
  15.  
  16. $ReportFileName = 'c:\whatever\some.file'
  17. $UserInputTimeoutSeconds = 3
  18.  
  19. # ask user for custom report prefix
  20. echo "Press any key in $UserInputTimeoutSeconds seconds to specify custom report name..."
  21. $customPrefix = waitForUserInput -TimeoutSeconds $UserInputTimeoutSeconds -Prompt "Report prefix"
  22. $customPrefix = $customPrefix -replace '[^\w]',''
  23. if($customPrefix){
  24. $reportDir = Split-Path -Parent $ReportFileName
  25. $reportSuffix = Split-Path -Leaf $ReportFileName
  26. $ReportFileName = "$reportDir\${customPrefix}_$reportSuffix"
  27. }
  28.  
  29. # ...
Add Comment
Please, Sign In to add comment