69 lines
1.7 KiB
PowerShell
69 lines
1.7 KiB
PowerShell
<#
|
|
.Synopsis
|
|
Creates AD Computer object in ITD OUs
|
|
.DESCRIPTION
|
|
Long description
|
|
.EXAMPLE
|
|
Example of how to use this cmdlet
|
|
.EXAMPLE
|
|
Another example of how to use this cmdlet
|
|
#>
|
|
function New-ITDADComputerServer
|
|
{
|
|
[CmdletBinding()]
|
|
Param
|
|
(
|
|
[string[]]
|
|
$ComputerName,
|
|
|
|
#[string]
|
|
#$AppName,
|
|
|
|
[PSCredential]
|
|
$Credential
|
|
)
|
|
|
|
Begin
|
|
{
|
|
|
|
Write-Verbose "Validate credentials, stop script if invalid."
|
|
If($Credential -eq "" -or $Credential -eq $null)
|
|
{
|
|
$Credential = Get-Credential -Message "Enter domain/OU administrator credentials. User name must be entered as a SAMAccountName (DOMAIN\username) or as a User Principal Name (username@domain.com)" -UserName $Credential
|
|
If($Credential -eq "" -or $Credential -eq $null)
|
|
{
|
|
Write-Warning "credentials missing - stopping script"
|
|
break
|
|
}
|
|
If((Test-ADCredential -Credential $Credential -ErrorAction Stop) -eq $false)
|
|
{
|
|
Write-Warning "Invalid credentials or locked account."
|
|
break
|
|
}
|
|
}
|
|
|
|
Import-Module ActiveDirectory
|
|
$OUdefault = "OU=Prod,OU=All-General,OU=Windows,OU=SERVERS,OU=COMPUTERS,OU=ITD,DC=ND,DC=GOV"
|
|
}
|
|
Process
|
|
{
|
|
ForEach($c in $ComputerName)
|
|
{
|
|
$Hostname=($c.split(".")[0]).ToUpper()
|
|
#If($AppName)
|
|
#{
|
|
|
|
#}
|
|
#Else
|
|
#{
|
|
$OUdestination = $OUdefault
|
|
#}
|
|
|
|
New-ADComputer -Name $Hostname -Path $OUdestination -Credential $Credential
|
|
}
|
|
}
|
|
End
|
|
{
|
|
}
|
|
}
|