Start-HadoopAdminShell.ps1 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. param(
  2. $credentialFilePath = "c:\hadoop\singlenodecreds.xml",
  3. $hadoopHome = "$env:HADOOP_HOME",
  4. $shellCmd = "`"$env:HADOOP_HOME\bin\hadoop.cmd`""
  5. )
  6. function Start-HadoopShell($message, $credentials)
  7. {
  8. if($credentials)
  9. {
  10. Start-Process cmd.exe -ArgumentList @("/k pushd `"$hadoopHome`" && $shellCmd && title Hadoop Admin Command Line") -Credential $creds
  11. }
  12. else
  13. {
  14. Start-Process cmd.exe -ArgumentList @("/k pushd `"$hadoopHome`" && $shellCmd && title Hadoop Command Line && echo: && echo $message")
  15. }
  16. }
  17. if (Test-Path ($credentialFilePath))
  18. {
  19. $import = Import-Clixml -Path $credentialFilePath
  20. $username = $import.Username
  21. try
  22. {
  23. $securePassword = $import.Password | ConvertTo-SecureString -ErrorAction Stop
  24. }
  25. catch
  26. {
  27. $message = "WARNING: Unable to decrypt credentials file for hadoop service user. The same user account used to install hadoop must be used to start the hadoop command shell. Hadoop admin commands will not be available."
  28. }
  29. if($securePassword)
  30. {
  31. $creds = New-Object System.Management.Automation.PSCredential $username, $securePassword
  32. Start-HadoopShell -credentials $creds
  33. }
  34. else
  35. {
  36. Start-HadoopShell -message $message
  37. }
  38. }
  39. else
  40. {
  41. Start-HadoopShell -message "WARNING: Credentials file for hadoop service user not found at $credentialFilePath. Hadoop admin commands will not be available."
  42. }