与CMD不用,在Powershell中我们不会去使用For语句,
以下为Powershell循环命令的示例,怎么用就看大家了
$result = Get-Content "c:testnewUser.csv"
$i=0
foreach($line in $result)
{
$arr = $line.split(",")
New-Mailbox -Alias $arr[19] -Name $arr[2] -LastName $arr[0] -FirstName $arr[1] -DisplayName $arr[3] -Initials '' -OrganizationalUnit $arr[17] -UserPrincipalName ($arr[19] + "@shelltongyi.com") -SamAccountName $arr[19] -Password $Temp -ResetPasswordOnNextLogon $true -Database $arr[18]
$i++
add-content -path "c:testa.log" -value ((get-date -format 'yyyy-MM-dd hh:mm:ss') + " " + $i.ToString() + " " + $arr[0] + " )
}
[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23700676/viewspace-1052356/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23700676/viewspace-1052356/