我需要調整此腳本以從CSV創建一批本地用戶,但跳過已經創建的帳戶。我可以建立得很好,但如何我省略已經存在從csv創建本地帳戶,但如何省略已創建的帳戶?
$computer = $Env:ComputerName
$text = "C:\accounts.csv"
$user = import-csv -path $text
foreach($strUser) in $user)
{
$user = $struser.user
$password = $struser.password
$description = $struser.description
$group = $struser.group
Clear-Host
$ObjOU = [ADSI]"WinNT://$computer"
$objUser = $objOU.Create("User", $user)
$objUser.setpassword($password)
$objUser.put("description",$description)
$objUser.SetInfo()
$objGroup = [ADSI]"WinNT://$computer/$group"
$objGroup.add("WinNT://$computer/$user")
$objGroup.SetInfo()
}
它失敗,原因是您必須提供有關的右手側的值表達式「 - 」操作。 在C:\ Windows \ TEMP \ AltirisScript0B427C10272370E8748.ps1:12 char:12 + If($ user - <<<< notin($ ObjOU.Children | Where {{_。SchemaClassName -eq'user'} )) + CategoryInfo:ParserError:(:) [],ParseException + FullyQualifiedErrorId:ExpectedValueExpression – CrumBum
我會爲此使用什麼表達式? – CrumBum