Guest User

Untitled

a guest
May 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. # START: Display name and purpose of invoked script
  2. $path = $MyInvocation.MyCommand.Definition
  3. Clear-Host
  4. Write-Host $path
  5. Write-Host " "
  6. Write-Host "This script will allow you to do the following in a single-step process:"
  7. Write-Host "(1) RENAME this computer"
  8. Write-Host "(2) JOIN it to MYDOMAIN"
  9. Write-Host "(3) MOVE it to a target OU"
  10. Write-Host "(4) REBOOT"
  11. Write-Host " "
  12. Pause
  13.  
  14.  
  15. # Function: PAUSE
  16. Function Pause ($Message = "Press any key to continue . . . ") {
  17. if ((Test-Path variable:psISE) -and $psISE) {
  18. $Shell = New-Object -ComObject "WScript.Shell"
  19. $Button = $Shell.Popup("Click OK to continue.", 0, "Script Paused", 0)
  20. }
  21. else {
  22. Write-Host -NoNewline $Message
  23. [void][System.Console]::ReadKey($true)
  24. Write-Host
  25. }
  26. Write-Host " "
  27. }
  28.  
  29. # Function: Define the parameters
  30. Function Define-Parameters {
  31.  
  32. # Specify new computer name, with validation and TRAP
  33. $WS_NewName = $null
  34. while ($null -eq $WS_NewName) {
  35. [ValidateLength(8,15)]$WS_NewName = [string](Read-Host -Prompt "NEW NAME of computer (8-15 chars.)" )
  36. TRAP {"" ;continue}
  37. }
  38. Write-Host " "
  39.  
  40. # Domain to join.
  41. $DomainToJoin = 'mydomain.net'
  42.  
  43. # Specify the target OU, with validation and trap
  44. $baseOU='OU=Offices OU,DC=mydomain,DC=net'
  45. $OU2 = $null
  46. while ($null -eq $OU2) {
  47. [ValidateLength(2,2)]$OU2 = [string](Read-Host -Prompt 'Target OU (TWO-LETTER code for your office)' )
  48. TRAP {"" ;continue}
  49. }
  50. Write-Host " "
  51. $LocDN = "OU=$OU2,$baseOU"
  52. }
  53.  
  54.  
  55.  
  56. # Function: Summary and confirmation screen for defined parameters.
  57. Function Confirm-Parameters {
  58. Write-Host "==========================================================================="
  59. Write-Host "Please confirm that you are joining this computer to
  60. $DomainToJoin (MYDOMAIN)"
  61. Write-Host "with the following parameters:"
  62. Write-Host ""
  63. Write-Host ""
  64. Write-Host "Computer's NEW NAME: $WS_NewName"
  65. # Write-Host "Domain to Join: $DomainToJoin"
  66. Write-Host "TARGET mission OU: $OU2"
  67. }
  68.  
  69.  
  70. # Call Define-Parameters Function
  71. Define-Parameters
  72.  
  73. # Call Confirm-Parameters Function
  74. Confirm-Parameters
  75.  
  76. <#
  77. Some more code here
  78. #>
  79.  
  80.  
  81. # FINAL COMMAND if all else works: Join the computer to the domain, rename it, and restart it.
  82. # Add-Computer -DomainName $DomainToJoin -OUPath $LocDN -NewName $WS_NewName -Restart
Add Comment
Please, Sign In to add comment