如何创建一个循环来补充信息与PowerShell中的AD [英] How to create a loop to add info in the AD with powershell
问题描述
我是那种在PowerShell中一个新手的是,是否有人可以告诉我怎么可以创建一个循环(目的是将信息添加到所有的人(用户名)在.csv列表)
这就是我现在得到,tryed很多事情,但仍然没有好。
导入模块的ActiveDirectory
$用户名=进口-CSV C:\ user.csv
SET-ADUser便有-Identity $用户名 - 公司公司名称
尝试foreach循环。
示例:
的foreach(在$用户名$用户)
{
//例如一些行动
SET-ADUser便有-Identity $用户 - 公司A公司
}
参考:
的http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/
我也建议你加入某种日志(使用附加内容或写入主机)来跟踪脚本的进度,如果文件中有很多条目的。
问候 Arcass
I am a kind of a newbie in Powershell yet, can someone please tell me how i can create a loop (purpose is to add the info to all the people (usernames) in the .CSV list)
This is what i got now, tryed many things but still no good..
Import-Module ActiveDirectory
$username = Import-Csv c:\user.csv
Set-ADuser -Identity $Username -Company "Company name"
Try a foreach loop.
Example:
foreach($user in $username)
{
//some action for example
Set-ADuser -Identity $user -Company "A Company"
}
Reference:
http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/
I'd also recommend adding some sort of logging (using either add-content or write-host) to track the progress of the script, if the file has a lot of entries.
regards Arcass
这篇关于如何创建一个循环来补充信息与PowerShell中的AD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!