PoshCode Archive  Artifact Content

Artifact 6f983bb5366bab74891eb6d95c07310ecdcd4789e2c8ff7b0dd02b5c47296180:

  • File Set-Domain.ps1 — part of check-in [d2b107f413] at 2018-06-10 13:03:25 on branch trunk — A function to join a domain (user: Andy Schneider size: 906)

# encoding: ascii
# api: powershell
# title: Set-Domain
# description: A function to join a domain
# version: 0.1
# type: function
# author: Andy Schneider
# license: CC0
# function: Set-Domain
# x-poshcode-id: 1969
# x-archived: 2010-07-17T18:33:50
#
# 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-Credential) 
			)
			
	$usage = "`$cred = get-credential `n"
	$usage += "Set-Domain -domain MyDomain -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)
	
	}