GinShell.Windows/Public/Add-GsDomain.ps1
|
function Add-GsDomain { [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory = $true)] [string]$DomainName, [Parameter(Mandatory = $true)] [string]$DomainUsername, [Parameter(Mandatory = $true)] [string]$Password, [Parameter()] [switch]$Restart ) try { Write-GsLog -Message "Preparing to join domain '$DomainName'..." -Type Info $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($DomainUsername, $securePassword) if ($PSCmdlet.ShouldProcess("This machine", "Join domain $DomainName")) { Add-Computer -DomainName $DomainName -Credential $credential -PassThru -Verbose -Force -Restart:$false Write-GsLog -Message "Successfully joined domain '$DomainName'." -Type Success if ($Restart) { Write-GsLog -Message "Restarting computer..." -Type Info Restart-Computer -Force } } } catch { Write-GsLog -Message "Failed to join domain: $_" -Type Error throw } } |