根据用户输入选择使用OUPath

时间:2018-05-08 09:48:30

标签: powershell

我制作了一个功能齐全的脚本,根据用户输入创建了新的用户帐户。然而,我无法弄清楚的一件事是为用户选择OUPath并使用该变量来创建一个useraccount。

我有静态变量,输入提示和要添加的参数。

这是输入提示:$ OUPath = Read-Host' INTERN / EXTERN'

这些是静态变量:$OUPath = 'OU=Intern,OU=Users,OU=Zero,DC=int,DC=zero,DC=com' This is the parameters to add: 'Path' = $OUPath

如果您有兴趣,这是我的脚本。我删除了所有不必要的变量:

while($true){


Copy-Item -Path "\\int.zero.com\zero\org\ICT\zero\SD\PS-Modules\Write-Ascii" -Destination "C:\Users\$Env:UserName\Documents\WindowsPowerShell\Modules\Write-Ascii" -Recurse -Force
Import-Module Write-Ascii
Write-Ascii -fore white "ZERO"
Write-Ascii -fore red "ZERO"
Write-Ascii -fore rainbow "version 3"


write-host -ForegroundColor Red "Goodmorning $Env:UserName"

$ErrorActionPreference = "SilentlyContinue"

#input prompts
$initials    = Read-Host 'VOORLETTERS'
$Firstname   = Read-Host 'VOORNAAM'
$Lastname    = Read-Host 'ACHTERNAAM'
$UserID      = Read-Host 'GEBRUIKERSNAAM'
$Alias2       = Read-Host 'ALIAS VOOR E-MAIL'
$department  = Read-Host 'AFDELING'
$title       = Read-Host 'FUNCTIE'
$description = Read-Host 'PERSONEELSNUMMER'
$OUPath      = Read-Host 'INTERN/EXTERN'

#static variables
$Password     = (ConvertTo-SecureString -AsPlainText 'Welcome01' -Force)
$Displayname  = "$lastname, $initials"
#$OUPath       = 'OU=Intern,OU=Gebruikers,OU=ZERO,DC=int,DC=zero,DC=com'
#$OUPath2      = 'OU=Extern,OU=Gebruikers,OU=ZERO,DC=int,DC=zero,DC=com'
$company      = 'ZERO'
$profilePath  = "\\int.zero.com\Users\Profiles\$UserID"
$OfficePhone  = '8888'
$department   = "$department"
$title        = "$title"
$description  = "$description"
$Name         = "$Firstname $Lastname"
$initials     = "$initials"

$OUPathValidate = $false
While ($OUPathValidate) {

    If ($OUPath.ToUpper() -eq 'INTERN') {
        $OUPath = 'OU=Intern,OU=Users,OU=ZERO,DC=int,DC=rpz,DC=com'
        $OUPathValidate = $true
    } ElseIf ($OUPath.ToUpper() -eq 'EXTERN') {
        $OUPath = 'OU=Extern,OU=Users,OU=ZERO,DC=int,DC=rpz,DC=com'
        $OUPathValidate = $true
    } Else {
        Write-Host 'That is not a valid input, please use INTER or EXTERN'
    }
}


#used to add parameters
$Parameters = @{
    'SamAccountName'        = $UserID
    'UserPrincipalName'     = $UserID
    'Name'                  = "$Firstname $initials $Lastname"
    'GivenName'             = $Firstname
    'Surname'               = $Lastname
    'DisplayName'           = $Displayname
    'AccountPassword'       = $password
    'ChangePasswordAtLogon' = $true
    'Enabled'               = $true
    'Path'                  = $OUPath
    'company'               = $company
    'department'            = $department
    'description'           = $description
    'title'                 = $title
    'profilePath'           = $profilePath
    'initials'              = $initials
    'OfficePhone'           = $OfficePhone



}

#used to add groupmembers to new users
import-module activedirectory
New-ADUser @Parameters

https://pastebin.com/pkPVQm7b

非常感谢帮助!

0 个答案:

没有答案