Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # START: Display name and purpose of invoked script
- $path = $MyInvocation.MyCommand.Definition
- Clear-Host
- Write-Host $path
- Write-Host " "
- Write-Host "This script will allow you to do the following in a single-step process:"
- Write-Host "(1) RENAME this computer"
- Write-Host "(2) JOIN it to MYDOMAIN"
- Write-Host "(3) MOVE it to a target OU"
- Write-Host "(4) REBOOT"
- Write-Host " "
- Pause
- # Function: PAUSE
- Function Pause ($Message = "Press any key to continue . . . ") {
- if ((Test-Path variable:psISE) -and $psISE) {
- $Shell = New-Object -ComObject "WScript.Shell"
- $Button = $Shell.Popup("Click OK to continue.", 0, "Script Paused", 0)
- }
- else {
- Write-Host -NoNewline $Message
- [void][System.Console]::ReadKey($true)
- Write-Host
- }
- Write-Host " "
- }
- # Function: Define the parameters
- Function Define-Parameters {
- # Specify new computer name, with validation and TRAP
- $WS_NewName = $null
- while ($null -eq $WS_NewName) {
- [ValidateLength(8,15)]$WS_NewName = [string](Read-Host -Prompt "NEW NAME of computer (8-15 chars.)" )
- TRAP {"" ;continue}
- }
- Write-Host " "
- # Domain to join.
- $DomainToJoin = 'mydomain.net'
- # Specify the target OU, with validation and trap
- $baseOU='OU=Offices OU,DC=mydomain,DC=net'
- $OU2 = $null
- while ($null -eq $OU2) {
- [ValidateLength(2,2)]$OU2 = [string](Read-Host -Prompt 'Target OU (TWO-LETTER code for your office)' )
- TRAP {"" ;continue}
- }
- Write-Host " "
- $LocDN = "OU=$OU2,$baseOU"
- }
- # Function: Summary and confirmation screen for defined parameters.
- Function Confirm-Parameters {
- Write-Host "==========================================================================="
- Write-Host "Please confirm that you are joining this computer to
- $DomainToJoin (MYDOMAIN)"
- Write-Host "with the following parameters:"
- Write-Host ""
- Write-Host ""
- Write-Host "Computer's NEW NAME: $WS_NewName"
- # Write-Host "Domain to Join: $DomainToJoin"
- Write-Host "TARGET mission OU: $OU2"
- }
- # Call Define-Parameters Function
- Define-Parameters
- # Call Confirm-Parameters Function
- Confirm-Parameters
- <#
- Some more code here
- #>
- # FINAL COMMAND if all else works: Join the computer to the domain, rename it, and restart it.
- # Add-Computer -DomainName $DomainToJoin -OUPath $LocDN -NewName $WS_NewName -Restart
Add Comment
Please, Sign In to add comment