tacticalrmm/scripts_wip/Win_AD_Join_Computer.ps1

67 lines
1.4 KiB
PowerShell
Raw Normal View History

2021-05-12 02:53:37 +00:00
<#
.SYNOPSIS
I do this
.DESCRIPTION
I really do a lot of this
.OUTPUTS
Results are printed to the console. Future releases will support outputting to a log file.
2021-05-12 02:53:37 +00:00
.NOTES
Change Log
V1.0 Initial release
V1.1 Parameterization; Error Checking with conditionals and exit codes
2021-05-12 02:53:37 +00:00
Reference Links: www.google.com
#>
param(
$domain,
$password,
$UserAccount,
$OUPath
)
$username = "$domain\$UserAccount"
$credential = New-Object System.Management.Automation.PSCredential($username, $secpassword)
if ([string]::IsNullOrEmpty($domain)) {
Write-Output "Domain must be defined. Use -domain <value> to pass it."
EXIT 1
}
if ([string]::IsNullOrEmpty($UserAccount)) {
Write-Output "User Account must be defined. Use -UserAccount <value> to pass it."
EXIT 1
}
if ([string]::IsNullOrEmpty($password)){
Write-Output "Password must be defined. Use -password <value> to pass it."
EXIT 1
}
else{
$password = ConvertTo-SecureString -string $password -asPlainText -Force
}
try{
if ([string]::IsNullOrEmpty($OUPath){
Write-Output "OU Path is not defined. Computer object will be created in the default OU."
Add-Computer -DomainName $domain -Credential $credential -Restart
EXIT 0
}
else {
Add-Computer -DomainName $domain -OUPath $OUPath -Credential $credential -Restart
EXIT 0
}
}
catch{
Write-Output "An error has occured."
EXIT 1
}
Exit $LASTEXITCODE