Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
519
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. # CC-BY-SA
  4.  
  5. function Set-Domain {
  6.     param(  [switch]$help,
  7.             [string]$domain=$(read-host "Please specify the domain to join"),
  8.             [System.Management.Automation.PSCredential]$credential = $(Get-Crdential)
  9.             )
  10.            
  11.     $usage = "`$cred = get-credential `n"
  12.     $usage += "Set-AvaDomain -domain corp.avanade.org -credential `$cred`n"
  13.     if ($help) {Write-Host $usage;exit}
  14.    
  15.     $username = $credential.GetNetworkCredential().UserName
  16.     $password = $credential.GetNetworkCredential().Password
  17.     $computer = Get-WmiObject Win32_ComputerSystem
  18.     $computer.JoinDomainOrWorkGroup($domain ,$password, $username, $null, 3)
  19.    
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement