Deleting Attribute if Present

$Attributegroup=Get-ADGroup -Identity GRpname -Properties EXT15 | select -expandproperty EXT15
if($Attributegroup -ne $null){set-ADGroup -Identity GRpname -clear EXT15 -verbose}

I am looking for a script which check if attributes “EXT15” in all groups in specific ou and if present delete the same, along with whatever value it possess

For testing I was trying for one group. I got the desired result, but feel not the right way. It is actually checking for the value instead of checking if the property is present or not. For some reason if the value is blank, this will skip, which I dont want. I want to delete the attribute itself, even if its blank

Any better way to work on this.

Also wondering if their is a possibility of log generation of specific deletion that I am doing or I need to do using PSCUstomObject.

Why checking before when you’re about to clear it anyway?

[quote quote=224271]Why checking before when you’re about to clear it anyway?

[/quote]
So that I can know how much from an ou had that list, which I cleared

So what’s the actual question? You need a loop to process more than one group and you need a condition to check if the desired attribute is filled or not. Then you store this information temporarily in a variable and clear the attribute. In the end you write the temprarily saved information to a channel of your choice.

Well the question is very clear. Let me know that I am not supposed to ask such question here. I am just looking to know a pointer if the attributes exist, not if the the attribute has a value and what exactly do you mean by my choice?

Isn’t this the channel to help or ask question on question?

 

Of course the attributes are there. It’s an AD all objects of the same object class have the same attributes. I think you may read up about active directory in general first. :wink:

I meant information channels like log files, event logs or data bases … a place where you store the information you collected.

Of course it is. But it’s a technical forum here. You have to ask a clear specific question to get reasonable answers. How to Ask Questions in a Technical Forum.

[quote quote=224616]

Rajesh wrote:
I am just looking to know a pointer if the attributes exist, not if the the attribute has a value …
Of course the attributes are there. It’s an AD all objects of the same object class have the same attributes. I think you may read up about active directory in general first. 😉
Rajesh wrote:
what exactly do you mean by my choice?
I meant information channels like log files, event logs or data bases … a place where you store the information you collected.
Rajesh wrote:
Isn’t this the channel to help or ask question on question?
  1. Of course it is. But it’s a technical forum here. You have to ask a clear specific question to get reasonable answers. How to Ask Questions in a Technical Forum.

    [/quote]

You don't need to teach me active directory. You yourself need to learn some ethics on answering or helping. This is second time I have I seen you responding and counter question unnecessarily without any help. Why can't you just keep quiet instead of dragging the topic.

I have got some.wonderful answer here but it seem people like you who spoils the forum.

Fyi, EXT15 is not an active directory attributes. It’s can attributes which is added manually.if it’s been there for all then it’s just common sense that why would ask even the question here.

Hi Rajesh,

Please check out the following links. I’m certain you can find the answers to your questions with these resources.

https://bit.ly/3aVRPxh

https://bit.ly/3aUXyn5

I hope you find this helpful.

[quote quote=224748]Hi Rajesh,

Please check out the following links. I’m certain you can find the answers to your questions with these resources.

https://bit.ly/3aVRPxh

https://bit.ly/3aUXyn5

I hope you find this helpful.

[/quote]
Thanks Doug.

Thought to share this out, as this might help someone looking for the same. The script wont be perfect, but it does it job and got the exact thing that I was looking for.

The below help to determine if the property is present or not.
$group.PSobject.Properties.Name -contains “ATTR15”

$groups= @()
$Attrexist= @()
$oupath=@()
$data=@()
$status=@()
$output=@()
$domain=@()

# Set the OU Path to searh
$oupath="OU=EST,DC=contonso,DC=com"

#set the Destination pathoutout of the script
$output="C:\temp\ATTR15\Attr15.csv"

#domain
$domain="contonso.com"

$groups=Get-ADGroup -SearchBase $oupath -server $domain -filter * -properties ATTR15

Foreach($group in $groups){
$Attrexist=$group.PSobject.Properties.Name -contains "ATTR15"
If ($Attrexist -eq $true){
    
  $data += [PSCustomObject]@{
   Name     = $group.name
   Domain =$domain
   ATTR15= $Attrexist
   }
set-ADGroup -Identity $group -server $domain -clear ATTR15  -verbose

}
}
$data |export-csv $output -NoTypeInformation

I’m curious. You only add one element to your custom object array when you find “ATTR15”, right? So the property “ATTR15” in all objects you collected is $true, right?

<p style=“text-align: left;”>[quote quote=224850]I’m curious. You only add one element to your custom object array when you find “ATTR15”, right? So the property “ATTR15” in all objects you collected is $true, right?

[/quote]
Nope, it resulted only on groups which has that attributes ATTR15 , as what I want and I have reconfirmed this.</p>

That’s exactly what I asked … so it’s “Yes”. Thanks. :wink: