Forum Discussion
which powershell conditions can be used for below scenario
To add, you could do a search for all computers in the ADNWE OU. Something like
$computers=get-adcomputer -filter * -properties * | where-object extensionattribute -ne 'HAW' | where-object distinguishedname -match 'ou=adnwe,ou=sgv,ou=workstations,ou=_ab,dc=abc,dc=com
foreach ($computer in $computers) {
set-adcomputer $computer -add @{ExtensionAttribute1="HAW}
}
To remove, you could do a search for all computers with a extensionattribute1 filled with HAW which is not present in the ADNWE OU. Something like
$computers=get-adcomputer -filter * -properties * | where-object extensionattribute -eq 'HAW' | where-object distinguishedname -notmatch 'ou=adnwe,ou=sgv,ou=workstations,ou=_ab,dc=abc,dc=com
foreach ($computer in $computers) {
set-adcomputer $computer -Clear "extensionAttribute1"
}
Does this work for you in your environment?