电源 Shell CSV 到 AD
Power Shell CSV to AD
也许有人可以帮忙?
我有一个脚本,它从 scv 获取参数并将它们放入 AD,脚本工作没有错误,但我没有从某些原因得到结果。
请帮忙!
Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach-Object -process {Write-Host $_ }
{Set-ADuser|]= -Identity $_.DisplayName -extensionattribute5 $_.extensionattribute5}
示例 scv
试试这个:
Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach {
Write-Host $_
Set-ADuser -Identity $_.DisplayName -Add @{extensionattribute5=$_.extensionattribute5}
}
您的代码已损坏。支撑不正确。此外,扩展属性使用 -Add 参数添加散列 table。
根据 the docs,Set-ADUser
上的 -Identity
参数必须是
之一
- 专有名称
- 一个 GUID (objectGUID)
- 安全标识符 (objectSid)
- SAM 帐户名 (sAMAccountName)
这意味着您不能将 CSV 中的 DisplayName 属性 用于此参数。
尝试:
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"
}
}
而不是 -Add @{extensionattribute5=$_.extensionattribute5}
,您可能更想要 -Replace @{extensionattribute5=$_.extensionattribute5}
。这在问题中不清楚
也许有人可以帮忙?
我有一个脚本,它从 scv 获取参数并将它们放入 AD,脚本工作没有错误,但我没有从某些原因得到结果。
请帮忙!
Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach-Object -process {Write-Host $_ }
{Set-ADuser|]= -Identity $_.DisplayName -extensionattribute5 $_.extensionattribute5}
示例 scv
试试这个:
Import-CSV -Path "$home\desktop\Scripts\test4.scv" | ForEach {
Write-Host $_
Set-ADuser -Identity $_.DisplayName -Add @{extensionattribute5=$_.extensionattribute5}
}
您的代码已损坏。支撑不正确。此外,扩展属性使用 -Add 参数添加散列 table。
根据 the docs,Set-ADUser
上的 -Identity
参数必须是
- 专有名称
- 一个 GUID (objectGUID)
- 安全标识符 (objectSid)
- SAM 帐户名 (sAMAccountName)
这意味着您不能将 CSV 中的 DisplayName 属性 用于此参数。
尝试:
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"
}
}
而不是 -Add @{extensionattribute5=$_.extensionattribute5}
,您可能更想要 -Replace @{extensionattribute5=$_.extensionattribute5}
。这在问题中不清楚