Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function waitForUserInput([parameter(mandatory=$true)][int]$TimeoutSeconds, [string]$Prompt){
- $counter = 0
- while($counter++ -lt $TimeoutSeconds){
- if(-not [console]::KeyAvailable){
- Start-Sleep -Seconds 1
- } else {
- $input = Read-Host -Prompt "$Prompt"
- break
- }
- }
- if($input){
- Write-Output "$input"
- }
- }
- $ReportFileName = 'c:\whatever\some.file'
- $UserInputTimeoutSeconds = 3
- # ask user for custom report prefix
- echo "Press any key in $UserInputTimeoutSeconds seconds to specify custom report name..."
- $customPrefix = waitForUserInput -TimeoutSeconds $UserInputTimeoutSeconds -Prompt "Report prefix"
- $customPrefix = $customPrefix -replace '[^\w]',''
- if($customPrefix){
- $reportDir = Split-Path -Parent $ReportFileName
- $reportSuffix = Split-Path -Leaf $ReportFileName
- $ReportFileName = "$reportDir\${customPrefix}_$reportSuffix"
- }
- # ...
Add Comment
Please, Sign In to add comment