Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for logindialog.ps

(view source code of logindialog.ps as plain text)

  1. param(
  2. 	[string]$UserName = $null,
  3. 	[switch]$TabDelimited,
  4. 	[switch]$h,
  5. 	[parameter( ValueFromRemainingArguments = $true )]
  6. 	[object]$invalidArgs
  7. )
  8.  
  9. if ( $h -or $invalidArgs ) {
  10. 	Write-Host
  11. 	Write-Host "LoginDialog.ps1,  Version 1.01"
  12. 	Write-Host "Present a login dialog, and return the user name and password"
  13. 	Write-Host
  14. 	Write-Host "Usage:  " -NoNewline
  15. 	Write-Host "./LoginDialog.ps1  [ username ]  [ -TabDelimited ]" -ForegroundColor White
  16. 	Write-Host
  17. 	Write-Host "Where:  " -NoNewline
  18. 	Write-Host "username           " -ForegroundColor White -NoNewline
  19. 	Write-Host "is the optional user name presented in the dialog"
  20. 	Write-Host "        -TabDelimited      " -ForegroundColor White -NoNewline
  21. 	Write-Host "tab delimited output (default delimiter: semicolon)"
  22. 	Write-Host
  23. 	Write-Host "Written by Rob van der Woude"
  24. 	Write-Host "http://www.robvanderwoude.com"
  25. 	Exit 1
  26. } else {
  27. 	Try
  28. 	{
  29. 		# Dialog asking for credentials
  30. 		$cred = Get-Credential $UserName
  31.  
  32. 		# Return username and password, delimited by a semicolon (default) or tab (switch -TabDelimited)
  33. 		Write-Host $cred.GetNetworkCredential( ).UserName -NoNewline
  34. 		if ( $TabDelimited ) {
  35. 			Write-Host "`t" -NoNewline
  36. 		} else {
  37. 			Write-Host ";" -NoNewline
  38. 		}
  39. 		Write-Host $cred.GetNetworkCredential( ).Password
  40. 	}
  41. 	Catch
  42. 	{
  43. 		Write-Host "-- Canceled --"
  44. 		Exit 1
  45. 	}
  46. }

page last modified: 2024-04-16; loaded in 0.0222 seconds