【发布时间】:2020-12-11 06:11:33
【问题描述】:
大家好,我目前正在学习 PowerShell,并且我有脚本可以创建一个 Active Directory 用户,我正在尝试将名字和姓氏 (firstname.lastname) 结合起来,并将其设置为 $logonname 所以用户不必输入该信息。是否有某种类型的命令用于实现这一目标?
import-module activedirectory
#Define variable
$OU ="OU=mine,DC=mine,DC=mine"
$firstname = Read-Host 'Enter New Users First Name'
$lastname = Read-Host 'Enter New Users Last Name'
$logonname = Read-Host 'Enter New Users Windows Logon Name'
$EmailAddress = "$logonname@mine.com"
$Description = Read-Host 'Job Title?'
$Landline = Read-Host 'Enter the Users Landline Phone (if applicable)'
$Mobile = Read-Host 'Mobile Phone? (If Applicable)'
$Password = Read-Host 'Please enter a secure password'
New-ADUser -Name "$firstname $lastname" -EmailAddress $EmailAddress -DisplayName "$firstname $lastname" -SamAccountName $logonname -Title $Description -UserPrincipalName "$logonname@mine.com" -GivenName $firstname -Surname $lastname -Description $Description -OfficePhone $Landline -MobilePhone $Mobile
Write-Host 'Setting Account Details...'
Write-Host 'Setting Password...'
Set-ADAccountPassword -Identity $logonname -NewPassword (ConvertTo-SecureString -AsPlainText "$Password" -Force)
Set-ADUser -Identity $logonname -PasswordNeverExpires $true
Write-Host 'Setting Home Directory to \\networklocation\Home'
Set-ADUser -Identity $logonname -HomeDirectory \\networklocation\home -HomeDrive H
Write-Host 'Enabling Account in Active Directory..
**NOTE**
The Account Will Take 30 Seconds To Enable, It Is Safe To Close The Script As Long as you See the "DONE" Prompt.'
Enable-ADAccount -Identity $logonname
Write-Host 'Done'
【问题讨论】:
-
$logonname = $firstname + $lastname
-
谢谢道格。如何在两者之间添加句点?我想像 ex.(david.banner) 一样拥有它。
标签: powershell active-directory