Powershell 管道获取aduser输出以在foreach循环中设置aduser
我正在尝试获取电话属性为空的用户列表,并用电话号码更新atrrib,到目前为止,我得到的是:Powershell 管道获取aduser输出以在foreach循环中设置aduser,powershell,Powershell,我正在尝试获取电话属性为空的用户列表,并用电话号码更新atrrib,到目前为止,我得到的是: $allen=gc "C:\0NIX\03SCRIPTS\TMP\jkirb\allen.txt" $phonenumber = "972-xxx-xxx" FOREACH ($user in $allen) { $nophone = get-aduser $user -pr *| where {$_.telephonenumber -eq $null} | select samaccountname
$allen=gc "C:\0NIX\03SCRIPTS\TMP\jkirb\allen.txt"
$phonenumber = "972-xxx-xxx"
FOREACH ($user in $allen)
{
$nophone = get-aduser $user -pr *| where {$_.telephonenumber -eq $null} | select samaccountname |ft -HideTableHeaders
Set-ADuser -identity "$nophone" -replace @{telephonenumber="$phonenumber"}
}
哪一个与此相关:
Set-ADuser:找不到标识为“Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData”的对象
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData'位于以下位置:
“DC=bhcs,DC=pvt”。
第7行字符:1
+设置ADuser-标识“$nophone”-替换@{telephonenumber=“$phonenumber”}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:ObjectNotFound:(Microsoft.Power…t.FormatEndData:ADUser)[Set ADUser],ADIdentityNotFoundException
+FullyQualifiedErrorId:找不到标识为“Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData”的对象
rosoft.PowerShell.Commands.Internal.Format.FormatteryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatteryData'
bhcs,DC=pvt',Microsoft.ActiveDirectory.Management.Commands.SetADUser当您使用任何Format-*cmdlet(在您的情况下是Format Table)时,您正在向对象添加一些自定义格式,这会破坏对象以供将来管道使用 请尝试以下方法:
$allen=gc "C:\0NIX\03SCRIPTS\TMP\jkirb\allen.txt"
$phonenumber = "972-xxx-xxx"
FOREACH ($user in $allen)
{
$nophone = get-aduser $user -pr *| where {$_.telephonenumber -eq $null}
Set-ADuser -identity "$nophone" -replace @{telephonenumber="$phonenumber"}
}