Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This will join a computer to a domain
  2. # Hugh Smalley
  3. # hsmalley@gmail.com
  4. # CC-BY-SA
  5.  
  6. function Set-Domain {
  7.     param(  [switch]$help,
  8.             [string]$domain=$(read-host "Please specify the domain to join"),
  9.             [System.Management.Automation.PSCredential]$credential = $(Get-Crdential)
  10.             )
  11.            
  12.     $usage = "`$cred = get-credential `n"
  13.     $usage += "Set-AvaDomain -domain corp.avanade.org -credential `$cred`n"
  14.     if ($help) {Write-Host $usage;exit}
  15.    
  16.     $username = $credential.GetNetworkCredential().UserName
  17.     $password = $credential.GetNetworkCredential().Password
  18.     $computer = Get-WmiObject Win32_ComputerSystem
  19.     $computer.JoinDomainOrWorkGroup($domain ,$password, $username, $null, 3)
  20.    
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement