积极答复者
csvde -i -f user.csv报错,怎么修改?

问题
-
csvde -i -f user.csv报错,怎么修改?
C:\>csvde -i -f user.csv
连接到“(null)”
用 SSPI 作为当前用户登录
从“userlist.csv”文件导入目录
读取属性表出错
0 个项目修改成功。
在程序中出现一个错误
没有写入日志文件。要生成日志文件,请
通过 -j 选项来指定日志文件路径。
我在网上查询到是属性: Initials (英文缩写) 这个是有字附限制的,不知道怎么修改?- 已编辑 sh-it-hello1025 2018年11月15日 12:33
答案
-
你好,
你可以使用下面的powershell来实现你的需求。
Import-Module ActiveDirectory $Users= Import-Csv d:\user123.Csv | Where-Object {$_.objectClass -eq "user" } $Password=Read-Host "Enter the password that you want to set" -AsSecureString foreach($User in $Users) { New-ADUser -Name $User.Name -AccountPassword $Password -path "ou=user1,DC=testabc,DC=com" -Enabled $true -PassThru }
最好的祝福,
Lee
Just do it.
- 已编辑 LeeSeenLiMicrosoft contingent staff, Moderator 2018年11月20日 9:28
- 已标记为答案 sh-it-hello1025 2018年11月20日 9:35
全部回复
-
命令是不是这样的:
Import-Csv -Path d:\user.csv | Select-Object -Property *- 已编辑 sh-it-hello1025 2018年11月16日 3:59
-
Select-Object -Property * 是什么意思?不选用Select-Object -Property * 会有什么问题?
- 已编辑 sh-it-hello1025 2018年11月16日 8:41
-
这是命令csvde -i -f f:\user.csv -k -j c:\的日志
连接到“(null)”
用 SSPI 作为当前用户登录
从“f:\user.csv”文件导入目录
加载条目
2: DC=newabccompany,DC=com
Attribute 0) objectClass: domainDNS
Attribute 1) distinguishedName: DC=newabccompany,DC=com
Attribute 2) instanceType: 5
Attribute 3) whenCreated: 20090211020955.0Z
Attribute 4) whenChanged: 20181031171927.0Z
Attribute 5) subRefs: DC=DomainDnsZones,DC=newabccompany,DC=com DC=ForestDnsZones,DC=newabccompany,DC=com CN=Configuration,DC=newabccompany,DC=com
Attribute 6) uSNCreated: 7537
Attribute 7) dSASignature:写
UNPRINTABLE BINARY(40) 文件出错
Attribute 8) uSNChanged: 7849801
Attribute 9) name: newabccompany
Attribute 10) objectGUID:写
UNPRINTABLE BINARY(16) 文件出错
Attribute 11) replUpToDateVector:写
UNPRINTABLE BINARY(48) 文件出错
Attribute 12) creationTime: 131854799670428729
Attribute 13) forceLogoff: -9223372036854775808
Attribute 14) lockoutDuration: -18000000000
Attribute 15) lockOutObservationWindow: -18000000000
Attribute 16) lockoutThreshold: 0
Attribute 17) maxPwdAge: -36288000000000
Attribute 18) minPwdAge: -864000000000
Attribute 19) minPwdLength: 0
Attribute 20) modifiedCountAtLastProm: 0
Attribute 21) nextRid: 1003
Attribute 22) pwdProperties: 0
Attribute 23) pwdHistoryLength: 24
Attribute 24) objectSid:写
UNPRINTABLE BINARY(24) 文件出错
Attribute 25) serverState: 1
Attribute 26) uASCompat: 1
Attribute 27) modifiedCount: 1
Attribute 28) auditingPolicy:写
UNPRINTABLE BINARY(2) 文件出错
Attribute 29) nTMixedDomain: 0
Attribute 30) rIDManagerReference: CN=RID Manager$,CN=System,DC=newabccompany,DC=com
Attribute 31) fSMORoleOwner: CN=NTDS Settings,CN=SERVER,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=newabccompany,DC=com
Attribute 32) systemFlags: -1946157056
Attribute 33) wellKnownObjects: B:32:6227F0AF1FC2410D8E3BB10615BB5B0F:CN=NTDS Quotas,DC=newabccompany,DC=com B:32:F4BE92A4C777485E878E9421D53087DB:CN=Microsoft,CN=Program Data,DC=newabccompany,DC=com B:32:09460C08AE1E4A4EA0F64AEE7DAA1E5A:CN=Program Data,DC=newabccompany,DC=com B:32:22B70C67D56E4EFB91E9300FCA3DC1AA:CN=ForeignSecurityPrincipals,DC=newabccompany,DC=com B:32:18E2EA80684F11D2B9AA00C04F79F805:CN=Deleted Objects,DC=newabccompany,DC=com B:32:2FBAC1870ADE11D297C400C04FD8D5CD:CN=Infrastructure,DC=newabccompany,DC=com B:32:AB8153B7768811D1ADED00C04FD8D5CD:CN=LostAndFound,DC=newabccompany,DC=com B:32:AB1D30F3768811D1ADED00C04FD8D5CD:CN=System,DC=newabccompany,DC=com B:32:A361B2FFFFD211D1AA4B00C04FD7D83A:OU=Domain Controllers,DC=newabccompany,DC=com B:32:AA312825768811D1ADED00C04FD8D5CD:CN=Computers,DC=newabccompany,DC=com B:32:A9D1CA15768811D1ADED00C04FD8D5CD:CN=Users,DC=newabccompany,DC=com
Attribute 34) objectCategory: CN=Domain-DNS,CN=Schema,CN=Configuration,DC=newabccompany,DC=com
Attribute 35) isCriticalSystemObject: TRUE
Attribute 36) gPLink: [LDAP://CN={070B56C4-9544-440B-9CC9-E5F48BC0C24F},CN=Policies,CN=System,DC=newabccompany,DC=com;0][LDAP://CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=newabccompany,DC=com;0]
Attribute 37) dSCorePropagationData: 16010101000000.0Z
Attribute 38) otherWellKnownObjects: B:32:1EB93889E40C45DF9F0C64D23BBB6237:CN=Managed Service Accounts,DC=newabccompany,DC=com
Attribute 39) masteredBy: CN=NTDS Settings,CN=SERVER,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=newabccompany,DC=com
Attribute 40) ms-DS-MachineAccountQuota: 10
Attribute 41) msDS-Behavior-Version: 4
Attribute 42) msDS-PerUserTrustQuota: 1
Attribute 43) msDS-AllUsersTrustQuota: 1000
Attribute 44) msDS-PerUserTrustTombstonesQuota: 10
Attribute 45) msDs-masteredBy: CN=NTDS Settings,CN=SERVER,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=newabccompany,DC=com
Attribute 46) msDS-IsDomainFor: CN=NTDS Settings,CN=SERVER,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=newabccompany,DC=com
Attribute 47) msDS-NcType: 0
Attribute 48) dc: newabccompany
项目已经存在,忽略项目。
3: OU=Domain Controllers,DC=newabccompany,DC=com
Attribute 0) objectClass: organizationalUnit
Attribute 1) distinguishedName: OU=Domain Controllers,DC=newabccompany,DC=com
Attribute 2) instanceType: 4
Attribute 3) whenCreated: 20090211020956.0Z
Attribute 4) whenChanged: 20120908035331.0Z
Attribute 5) uSNCreated: 7642
Attribute 6) uSNChanged: 7642
Attribute 7) name: Domain Controllers
Attribute 8) objectGUID:写
UNPRINTABLE BINARY(16) 文件出错
Attribute 9) systemFlags: -1946157056
Attribute 10) objectCategory: CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=newabccompany,DC=com
Attribute 11) isCriticalSystemObject: TRUE
Attribute 12) gPLink: [LDAP://CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System,DC=newabccompany,DC=com;0]
Attribute 13) dSCorePropagationData: 16010101000000.0Z
Attribute 14) ou: Domain Controllers
Attribute 15) description: Default container for domain controllers
Attribute 16) showInAdvancedViewOnly: FALSE
在 3: 不会执行 行添加出错
服务器边的错误为 "修改操作非法。不允许该修改的某个方面。"
成功地修改了 0 个条目。
在程序中出现一个错误 -
你好,
请问你是否想要通过CSV文件恢复已经被删除的ADuser, 除了使用csv文件来恢复被删除的aduser账号,我建议你去回收站去查看这些被删除的账号是否仍然存在,或者通过ldp查看这些账号是否已经消失。 你可以从中直接恢复。
或者你可以使用下面的powershell来进行恢复。
Import-Module ActiveDirectory $Users= Import-Csv c:\user.csv $Password=Read-Host "Enter the password that you want to set" -AsSecureString foreach($User in $Users) { New-ADUser -Name $User.LoginName -Surname $User.LastName -GivenName $User.FirstName -EmailAddress $User.Email -SamAccountName $User.LoginName -AccountPassword $Password -DisplayName $User.DisplayName -Country $User.Country -City $User.City -path "" -Enabled $true -PassThru }
当然你也需要自己的环境对这个脚本进行一些特定的修改, 首先修改csv文件修改文件路径,其次要在运行powershell的时候按照提示输入你想要设置的密码,最后在最后一行的-path的地方加入这些aduser应该要保存的路径,例如 "OU=LAB,DC=Techibee,DC=AD"
最好的祝福,
Lee
Just do it.
-
-
1. 新用户的密码,如果你想要统一设置密码,我可以帮助你修改代码。
2. 你只需要将这个路径修改就好了,我提供的可以算是完整的powershell命令了,“OU=IT,DC=testabc,DC=com”, 类似这样的就可以了。
New-ADUser -Name $User.LoginName -Surname $User.LastName -GivenName $User.FirstName -EmailAddress $User.Email -SamAccountName $User.LoginName -AccountPassword $Password -DisplayName $User.DisplayName -Country $User.Country -City $User.City -path "OU=IT,DC=testabc,DC=com" -Enabled $true -PassThru
在这段代码-path的地方插入就行了,具体的路径你需要根据自己公司情况编写。
此外我还认为,作为一个公司的AD管理员,你需要学习一些powershell的基础知识。
请到以下链接进行基础知识的学习,
Microsoft Virtual Academy - Microsoft PowerShell入门
Best Regards,
Just do it.
- 已编辑 LeeSeenLiMicrosoft contingent staff, Moderator 2018年11月19日 5:42
-
运行有报错,原先文件名是2018.ps1,后来修改为文件名是aa.ps1。
Import后面有没有空格? Import-Module ActiveDirectory 还是 Import -Module ActiveDirectory
PS F:\> 2018.ps1
数字常量无效: 2018.。
所在位置 行:1 字符: 6
+ 2018. <<<< ps1
+ CategoryInfo : ParserError: (2018.:String) [], ParentContainsEr
rorRecordException
+ FullyQualifiedErrorId : BadNumericConstant
PS F:\> aa.ps1
无法将“aa.ps1”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的
拼写,如果包括路径,请确保路径正确,然后重试。
所在位置 行:1 字符: 7
+ aa.ps1 <<<<
+ CategoryInfo : ObjectNotFound: (aa.ps1:String) [], CommandNotFo
undException
+ FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: 未找到命令 aa.ps1,但它确实存在于当前位置。Windows Power
Shell 默认情况下不从当前位置加载命令。如果信任此命令,请改为键入 ".\aa.ps1"。有
关更多详细信息,请参阅 "get-help about_Command_Precedence"。 -
powershell真的挺难的。胜利的曙光就要到来了。
PS C:\Users\admin> get-executionpolicy
Restricted
PS C:\Users\admin> set-executionpolicy remotesigned
执行策略更改
执行策略可以防止您执行不信任的脚本。更改执行策略可能会使您面临
about_Execution_Policies 帮助主题中所述的安全风险。是否要更改执行策略?
[Y] 是(Y) [N] 否(N) [S] 挂起(S) [?] 帮助 (默认值为“Y”): Y
Set-ExecutionPolicy : 对注册表项“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerSh
ell\1\ShellIds\Microsoft.PowerShell”的访问被拒绝。
}
我修改注册表权限,再运行还是报错。
PS F:\> F:\2018.ps1
一元运算符“-”后缺少表达式。
所在位置 F:\2018.ps1:7 字符: 4
+ - <<<< DisplayName $User.DisplayName -Country $User.Country -City $User.City -path "OU=IT,DC=testabc,DC=com" -Enabled $true -PassThru
+ CategoryInfo : ParserError: (-:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingExpressionAfterOperator -
这个脚本还有什么错误?
Import-Module ActiveDirectory
$Users= Import-Csv F:\user.csv
$Password=Read-Host "Enter the password that you want to set" -AsSecureString
foreach($User in $Users)
{
New-ADUser -Name $User.LoginName -Surname $User.LastName -GivenName $User.FirstName -EmailAddress $User.Email -SamAccountName $User.LoginName -AccountPassword $Password
-DisplayName $User.DisplayName -Country $User.Country -City $User.City -path "OU=IT,DC=testabc,DC=com" -Enabled $true -PassThru
} -
请把2018.ps1文件发送我的QQ邮箱吧, 1160096943@qq.com ,谢谢!
- 已编辑 sh-it-hello1025 2018年11月19日 7:43
-
脚本能够运行,但还有报错。
New-ADUser : 无法对参数“Name”执行参数验证。该参数为 Null 或为空。请提供一个不
为 Null 或不为空的参数,然后重试此命令。
所在位置 F:\2018.ps1:6 字符: 19
+ New-ADUser -Name <<<< $User.LoginName -Surname $User.LastName -GivenName $
User.FirstName -EmailAddress $User.Email -SamAccountName $User.LoginName -Accou
ntPassword $Password -DisplayName $User.DisplayName -Country $User.Country -Cit
y $User.City -path "OU=IT,DC=testabc,DC=com" -Enabled $true -PassTh
ru
+ CategoryInfo : InvalidData: (:) [New-ADUser], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ
eDirectory.Management.Commands.NewADUser- 已编辑 sh-it-hello1025 2018年11月19日 8:04
-
你好,
你可以使用下面的powershell来实现你的需求。
Import-Module ActiveDirectory $Users= Import-Csv d:\user123.Csv | Where-Object {$_.objectClass -eq "user" } $Password=Read-Host "Enter the password that you want to set" -AsSecureString foreach($User in $Users) { New-ADUser -Name $User.Name -AccountPassword $Password -path "ou=user1,DC=testabc,DC=com" -Enabled $true -PassThru }
最好的祝福,
Lee
Just do it.
- 已编辑 LeeSeenLiMicrosoft contingent staff, Moderator 2018年11月20日 9:28
- 已标记为答案 sh-it-hello1025 2018年11月20日 9:35