Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Set-ADObject Cannot find an object

$
0
0

I have the following scripts its erroring out and I'm not sure why.

Import-Module ActiveDirectory

import-csv "c:\test scripts\output-Users3.csv" | % {

Set-ADObject $_.saMAccountName -replace @{msExchHideFromAddressLists=$false}
}

Set-ADObject : Cannot find an object with identity: 'ascott4' under: 'DC=domain,DC=com'.
At line:9 char:1
+ Set-ADObject $_.saMAccountName -replace @{msExchHideFromAddressLists=$false}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (ascott4:ADObject) [Set-ADObject], ADIdentityNotFoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: 'ascott4' under: 'DC=domain,DC=com'.,Microsoft.ActiveDirectory.Management.Commands.SetADObject

 I figured out my problem

Updated code:

Import-Module ActiveDirectory

import-csv "c:\test scripts\output-Users3.csv" | % {

Get-ADUser $_.sAMAccountName | Set-ADObject -replace @{msExchHideFromAddressLists=$false}


Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images