我正在尝试通过PowerShell中的部门绑定来批量创建帐户。我目前正在使用if..elseif..else
脚本,它对我不起作用。然后,部门代码if..elseif
将突破两个不同的if
语句,具体取决于帐户是否以“x”或“y”开头,因为帐户设置不同而需要将其分开。一些部门代码也将从0开始。我通过将命令放在引号中来简化我的脚本。
$Users = Import-Csv -Delimiter "," -Path "C:\Createuser.csv"
Import-Module ActiveDirectory
foreach ($User in $Users) {
$Displayname = $User.LastName + ", " + $User.Firstname
$ContractorDisplayname = $User.LastName + ", " + $User.Firstname + " (Contractor)"
$UserFirstname = $User.FirstName
$UserLastname = $User.LastName
$ContractorLastName = $User.LastName + ".Contractor"
$Department = $User.Department
$Description = $User.Description
$OU = $User.OU
$SAM = $User.SAM
$Password = $User.Password
$Manager = $User.Manager
$ManagerName = Get-ADUser -Identity $Manager -Properties samaccountname
if ($Department -in '005','367','RR1','411') {
if ($SAM -like 'x*') {".\GoldenContractorADscript.ps1"}
if ($SAM -like 'y*') {".\GoldenADscript.ps1"}
} elseif ($Department -in 'S11','222','054') {
".\StratasADscript.ps1"
} else {
if ($SAM -like 'x*') {".\StandardContractorADscript.ps1"}
if ($SAM -like 'y*') {".\StandardEmployeeADscript.ps1"}
}
}