Deleting Attribute if Present

Welcome Forums General PowerShell Q&A Deleting Attribute if Present

  • This topic has 12 replies, 3 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 12 reply threads
  • Author
    Posts
    • #224262
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant
      $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.

    • #224271
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

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

    • #224328
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

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

      So that I can know how much from an ou had that list, which I cleared

    • #224436
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      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.

    • #224529
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      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?

       

    • #224616
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      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. 😉

      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.

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

      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.

    • #224718
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      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. 😉

      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.

      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.

      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.

    • #224748
      Participant
      Topics: 3
      Replies: 340
      Points: 1,120
      Helping Hand
      Rank: Community Hero

      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.

    • #224757
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      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.

      Thanks Doug.

    • #224838
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      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
      
    • #224850
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      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?

    • #224958
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      <p style=”text-align: left;”>

      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?

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

    • #224964
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

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

Viewing 12 reply threads
  • You must be logged in to reply to this topic.