2021-05-12 02:53:37 +00:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
I do this
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
I really do a lot of this
|
|
|
|
|
|
|
|
.OUTPUTS
|
2021-06-19 02:43:26 +00:00
|
|
|
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
|
2021-06-19 02:43:26 +00:00
|
|
|
V1.1 Parameterization; Error Checking with conditionals and exit codes
|
2021-05-12 02:53:37 +00:00
|
|
|
|
|
|
|
Reference Links: www.google.com
|
|
|
|
#>
|
|
|
|
|
2021-06-19 02:43:26 +00:00
|
|
|
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
|