Power Shell CSV到AD [英] Power Shell CSV to AD
问题描述
也许有人可以提供帮助?
我有一个脚本,它将来自scv的参数放入AD中,脚本工作没有错误,但是我没有某些原因的结果。
请帮忙!
Maybe someone can to help?
I have a script it take parameters from scv and put them to AD, script work without mistakes but I`m does not have results from some reasone.
Please help!
Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach-Object -process {Write-Host $_ }
{Set-ADuser|]= -Identity $_.DisplayName -extensionattribute5 $_.extensionattribute5}
示例scv
推荐答案
根据文档, Set-ADUser <上的
-Identity
参数/ code>必须是以下项之一
According to the docs, the -Identity
parameter on Set-ADUser
must be one of
- 专有名称
- GUID(objectGUID )
- 安全标识符(objectSid)
- SAM帐户名(sAMAccountName)
- A distinguished name
- A GUID (objectGUID)
- A security identifier (objectSid)
- A SAM account name (sAMAccountName)
这意味着您不能使用CSV中的DisplayName属性作为该参数。
This means that you cannot use the DisplayName property from the CSV for this parameter.
尝试:
Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach-Object {
$user = Get-ADUser -Filter "DisplayName -eq '$($_.DisplayName)'" -Properties DisplayName -ErrorAction SilentlyContinue
if ($user) {
Write-Host "Setting extensionattribute5 property for user $($_.DisplayName)"
$user | Set-ADuser -Add @{extensionattribute5=$_.extensionattribute5}
}
else {
Write-Warning "User $($_.DisplayName) could not be found"
}
}
而不是-添加@ { extensionattribute5 = $ _。extensionattribute5}
,您可能更希望 -Replace @ {extensionattribute5 = $ _。extensionattribute5}
。这个问题不清楚
Instead of -Add @{extensionattribute5=$_.extensionattribute5}
, you may rather want -Replace @{extensionattribute5=$_.extensionattribute5}
. This isn't clear in the question
这篇关于Power Shell CSV到AD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!