PoshCode Archive  Artifact Content

Artifact 4512c56d77531a18da7c2965835072598dea7cafd3bfcad1d521c2318fbd9292:

  • File Set-Domain.ps1 — part of check-in [f9352a789f] at 2018-06-10 13:53:42 on branch trunk — A function to join a domain (user: unknown size: 916)

# encoding: ascii
# api: powershell
# title: Set-Domain
# description: A function to join a domain
# version: 0.1
# type: function
# license: CC0
# function: Set-Domain
# x-poshcode-id: 534
# x-derived-from-id: 1102
# x-archived: 2009-11-15T11:52:35
#
# Andy Schneider
# Get-powershell.com
#
function Set-Domain {
	param(	[switch]$help,
			[string]$domain=$(read-host "Please specify the domain to join"),
			[System.Management.Automation.PSCredential]$credential = $(Get-Crdential) 
			)
			
	$usage = "`$cred = get-credential `n"
	$usage += "Set-AvaDomain -domain corp.avanade.org -credential `$cred`n"
	if ($help) {Write-Host $usage;exit}
	
	$username = $credential.GetNetworkCredential().UserName
	$password = $credential.GetNetworkCredential().Password
	$computer = Get-WmiObject Win32_ComputerSystem
	$computer.JoinDomainOrWorkGroup($domain ,$password, $username, $null, 3)
	
	}