locked
Knowledge Bit: Diplaying an MV Schema RRS feed

  • General discussion

  • I'm obviously a big fan of PowerShell.  Two of my favourite things about it are:

    • it makes XML parsing a breeze
    • it makes script output pretty

    If you need to document an MV schema then this script might come in handy.  Otherwise if you just want to see how to use a custom object in PowerShell to make output a little nicer, then give this a shot.

    Note: there is a lot more attribute details located elsewhere in the MV XML (type,indexing,multi-valued).  For the sake of this script I am only looking for the object:attribute bindings.

    ### Get the folder where the script is located
    
    $configFolder = (Split-Path -parent $MyInvocation.MyCommand.Definition)
    
    
    
    ### Load the MV XML
    
    ### In this case I assume the MV.XML file is located in the same folder as THIS script
    
    [XML]$mvXML = Get-Content (Join-Path $configFolder "MV.XML")
    
    
    
    ### Create an empty array
    
    $mvAttributes = @()
    
    
    
    ###
    
    ### Loop through the object types
    
    ###
    
    foreach($objectType in $mvXML.'saved-mv-configuration'.'mv-data'.schema.dsml.'directory-schema'.class)
    
    {
    
     ###
    
     ### Loop through the bindings for the current object type
    
     ###
    
     foreach($attributeType in $objectType.attribute)
    
     {
    
      ### Create a custom object for pretty output
    
      $mvAttribute = New-Object PSObject
    
      $mvAttribute | Add-Member -MemberType noteproperty -name 'ObjectType' -value $objectType.name
    
      $mvAttribute | Add-Member -MemberType noteproperty -name 'AttributeType' -value $attributeType.ref.Replace('#',$null)
    
      $mvAttribute | Add-Member -MemberType noteproperty -name 'AttributeRequired' -value $attributeType.required
    
      
    
      ### Add our pretty object to the array
    
      $mvAttributes += $mvAttribute
    
     }
    
    }
    
    
    
    ### Put out to the Grid
    
    $mvAttributes | Out-GridView
    
    

     

    Out-GridView tips:

    • Try CTRL-A in the grid, then copy and paste into Excel
    • Try sorting on the columns
    • Try using the "Add Criteria" button to filter the results directly in the grid

     


    CraigMartin – Edgile, Inc. – http://identitytrench.com
    • Edited by Craig Martin Monday, August 9, 2010 7:00 PM added gridview tips
    Monday, August 9, 2010 6:23 PM