how to delete an array value from hash table

Welcome Forums General PowerShell Q&A how to delete an array value from hash table

  • This topic has 1 reply, 1 voice, and was last updated 1 month ago by
    Participant
    .
Viewing 1 reply thread
  • Author
    Posts
    • #233686
      Participant
      Topics: 11
      Replies: 9
      Points: 110
      Rank: Participant

      Hi All,

      roles : {@{databaseName=sales; roleName=readWrite}, @{databaseName=marketing; roleName=read}}

      I tried uwith  below 3 attempts to delete databasename=marketing , roleName=read from roles , but could not.

      #if my input $dbname = “marketing”
      if ($atlasdbname -eq $dbname)
       {
      1) $rol = $rol.Remove @{databaseName=$dbname;roleName=$rolename}
        2)  $rol = $rol.Remove(‘databaseName’,’roleName’)
      3)$rol[‘databaseName’] = ($rol[‘databaseName’] | ?{$_ -ne ‘$dbname’})
      I want to delete an entry from hash table($rol) with values , databaseName=marketing and roleName=read  can you please let me know the issue with above code .
      i also tried ,  Cast it to [System.Collections.ArrayList], which is mutable, then remove an element from it:
      $rol = [System.Collections.ArrayList]$rol
      $rol = $rol.Remove(‘marketing’,’read’)
      That did not work either
      Thank you
      • This topic was modified 1 month ago by pk30.
    • #233737
      Participant
      Topics: 11
      Replies: 9
      Points: 110
      Rank: Participant

      It is resolved with below command

      $rolnew = $rol | ? {$_.databaseName -ne $dbname}
Viewing 1 reply thread
  • You must be logged in to reply to this topic.