[英]How can I create an AD user via PowerShell prompting for options?
I'm trying to create a PowerShell script which will create users based on template users I've created. 我正在尝试创建一个PowerShell脚本,它将基于我创建的模板用户来创建用户。 The initial steps I'm trying to figure out are below: 我尝试找出的初始步骤如下:
Can somebody please point me in the right direction of how I would go about getting started with this script? 有人可以为我指出该脚本入门的正确方向吗?
Thanks in advance for any assistance! 在此先感谢您的协助!
Well, to prompt for user input you want to use the Read-Host
cmdlet, such as 好吧,要提示用户输入您想使用Read-Host
cmdlet,例如
$name = Read-Host -Prompt 'Enter your name'
The most up to date information can be found on Microsoft's website for the cmdlet. 可以在Microsoft网站上找到该cmdlet的最新信息。 I hope this points you in the right direction. 我希望这可以为您指明正确的方向。
Beware, this is not suitable for password prompts! 当心,这不适合密码提示!
This TechNet article and its children give you a very broad range of cmdlets related to Active Directory, most of which are very intuitively named. 这篇TechNet文章及其子级为您提供与Active Directory相关的非常广泛的cmdlet,其中大多数名称都非常直观地命名。 You'll probably be interested in ones such as: 您可能会对以下内容感兴趣:
As mentioned in Answer #1, Read-Host will let you prompt for input. 如答案1所述,“ 读取主机”将提示您输入信息。
In order to process a number of different options for location as per the third bullet point in your question, you may use a switch statement. 为了根据问题的第三个要点处理许多不同的位置选项,可以使用switch语句。
$Location = Read-Host "Enter user's location"
Switch ($Location) {
"First Floor" { } #Add code to add user to First Floor Groups
"Second Floor" { }
}
One issue you may run into here is that there is a very wide range of what the users of this script could potentially enter for the location, such as "First Floor" versus "first floor" versus "1st floor." 您可能会遇到的一个问题是,此脚本的用户可能会为该位置输入非常广泛的内容,例如“一楼”与“一楼”与“一楼”。 As such, you may want to up the ante a bit and use System.Management.Automation.Host.ChoiceDescription
for this task instead of Read-Host
. 因此,您可能需要稍微System.Management.Automation.Host.ChoiceDescription
准备,并使用System.Management.Automation.Host.ChoiceDescription
代替此任务来使用Read-Host
。 Take a look at this TechNet article for more information. 请参阅此TechNet文章以了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.