{"id":1340,"date":"2009-04-06T06:00:03","date_gmt":"2009-04-06T14:00:03","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2009\/04\/06\/up-another-powershell-tree\/"},"modified":"2009-06-01T08:13:44","modified_gmt":"2009-06-01T16:13:44","slug":"up-another-powershell-tree","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2009\/04\/06\/up-another-powershell-tree\/","title":{"rendered":"Up another PowerShell Tree"},"content":{"rendered":"<p>A few weeks ago I <a href=\"http:\/\/www.sapien.com\/blog\/2009\/03\/25\/powershell-tree\/\" target=\"_blank\">posted<\/a> a PowerShell script that created a directory tree, like the TREE command from the CMD shell. Then while testing something new in <a href=\"http:\/\/www.primaltools.com\/freetools\/\" target=\"_blank\">PrimalForms<\/a>, I realized I had a literal form object, a tree view, that I could use. So I put together a short script that creates a graphical tree for a given directory, along with the file counts and sizes from my original scripts.\u00a0 As a bonus, because I now had a graphical interface I could do things such as display empty folders in a different color. The script not only gives you a handy tool but also serves as a demonstration on how to use a TreeView control.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/04\/treeform.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" style=\"border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 5px 5px 0px; border-right-width: 0px\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/04\/treeform-thumb.png\" border=\"0\" alt=\"treeform\" width=\"244\" height=\"186\" \/><\/a><\/p>\n<p>The script, TreeForm.ps1, will default to the %TEMP% directory, but you can specify a path parameter from the command prompt:<\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff; font-size: x-small;\">PS C:\\scripts\\&gt; .\\treeform.ps1 -path c:\\users\\jeff\\documents\\sapien<\/span><\/p>\n<p>Once the script has been launched, all you need to do is type in a new directory path and click the Build Tree button. The script will expand the first level of folders from the root. You can expand and collapse folders by clicking the +\/- symbols. Or use the Expand All toggle button. The button text will change depending on the tree&#8217;s state.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$Toggle=<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">{<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #0000ff\">if<\/span> ($blnExpandAll)<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      $root.Collapse()<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      $btnControl.text=<span style=\"color: #006080\">\"Expand All\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      $blnExpandAll=$False<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      }<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">   <span style=\"color: #0000ff\">else<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">       $root.ExpandAll()<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">       $btnControl.text=<span style=\"color: #006080\">\"Collapse All\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">       $blnExpandAll=$True<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      }<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #008000\">#select the top node<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $treeview1.TopNode=$root<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $form1.Refresh()<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">}<\/pre>\n<\/div>\n<\/div>\n<p>There is a IsExpanded boolean property you can use to determine if a given node is expanded or not, but I defined my own variable since I wanted to track the state of the entire tree.<\/p>\n<p>The script creates a basic Windows form, including a TreeView control.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$form1 = New-Object System.Windows.Forms.Form<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$statusBar1 = New-Object System.Windows.Forms.StatusBar<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$btnUpdate = New-Object System.Windows.Forms.Button<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$btnControl = New-Object System.Windows.Forms.Button<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$txtPath = New-Object System.Windows.Forms.TextBox<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$treeView1 = New-Object System.Windows.Forms.TreeView<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState<\/pre>\n<\/div>\n<\/div>\n<p>When the form is shown, the script runs the BuildTree script block which first removes any existing tree nodes.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$BuildTree=<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">{<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #008000\">#clear existing nodes if any<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #0000ff\">if<\/span> ($root)<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    {<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $treeview1.Nodes.remove($root)<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $form1.Refresh()<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    }<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $path=$txtPath.Text<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    Function Get-SubFolder {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        Param([string]$path,<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">              [system.Windows.Forms.TreeNode]$parent )<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $statusbar1.Text=<span style=\"color: #006080\">\"Analyzing $path\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\u00a0<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $subdirs = dir $path | where {$_.GetType() <span style=\"color: #cc6633\">-match<\/span> <span style=\"color: #006080\">\"directoryInfo\"<\/span>}<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        <span style=\"color: #0000ff\">if<\/span> ($subdirs)<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">            <span style=\"color: #0000ff\">foreach<\/span> ($subdir <span style=\"color: #0000ff\">in<\/span> $subdirs) {<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $subfiles=dir $subdir.fullname | where {$_.GetType() <span style=\"color: #cc6633\">-match<\/span> <span style=\"color: #006080\">\"FileInfo\"<\/span>}<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $stats=$subfiles | Measure-Object -sum length<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                [int64]$subcount=$stats.count<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                [int64]$subsize=$stats.sum<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $leaf=(<span style=\"color: #006080\">\"{0} ({1} files {2} KB)\"<\/span> -f ($subdir.name,$subcount,(<span style=\"color: #006080\">\"{0:N2}\"<\/span> -f ($subsize\/1KB))))<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $node = New-Object System.Windows.Forms.TreeNode<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $node.Text=$leaf<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $node.name=$subdir.name<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                <span style=\"color: #008000\">#Write-Host (\"Adding {0} to {1}\" -f $node.name,$parent.name)<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                $parent.nodes.add($node) | Out-Null<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">                Get-SubFolder  -path $subdir.fullname -parent $node<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">            } <span style=\"color: #008000\">#end foreach<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        } <span style=\"color: #008000\">#end if<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\u00a0<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #0000ff\">if<\/span> ($parent.Nodes.count <span style=\"color: #cc6633\">-eq<\/span> 0 -and $subsize <span style=\"color: #cc6633\">-eq<\/span> 0)<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">     {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">         <span style=\"color: #008000\">#empty directory so change font color<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">         $parent.ForeColor=[System.Drawing.Color]::FromArgb(255,192,0,192)<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">     }<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"> } <span style=\"color: #008000\">#end Get-Subfolder function<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #008000\">#Turn off the error pipeline<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $ErrorActionPreference=<span style=\"color: #006080\">\"SilentlyContinue\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #0000ff\">if<\/span> ((Get-Item $path).exists)<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $data=dir $path<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $statusbar1.Text=<span style=\"color: #006080\">\"Analyzing $path\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $files=$data | where {$_.GetType() <span style=\"color: #cc6633\">-match<\/span> <span style=\"color: #006080\">\"FileInfo\"<\/span>}<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        [int64]$count=$files.count<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        [int64]$size=($files | Measure-Object -Sum Length).sum<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        <span style=\"color: #008000\">#write the tree root<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $leaf=(<span style=\"color: #006080\">\"{0} ({1} files {2} KB)\"<\/span> -f $path,$count,(<span style=\"color: #006080\">\"{0:N2}\"<\/span> -f ($size\/1KB)))<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $root = New-Object System.Windows.Forms.TreeNode<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $root.text = $leaf<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $root.Name = $path<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $treeView1.Nodes.Add($root)|Out-Null<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        <span style=\"color: #008000\">#enumerate child folders<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        Get-SubFolder -path $path -parent $root<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $statusbar1.Text=<span style=\"color: #006080\">\"Ready\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    }<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #0000ff\">else<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    {<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">        $statusbar1.text= <span style=\"color: #006080\">\"Failed to find $path\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    }<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #008000\">#expand the root node<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $root.Expand()<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $blnExpandAll=$False<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #008000\">#select the top node<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $treeview1.TopNode=$root<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    <span style=\"color: #008000\">#set the toggle button<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">    $btnControl.text=<span style=\"color: #006080\">\"Expand All\"<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">} #<span style=\"color: #0000ff\">end<\/span> Build Tree<\/pre>\n<\/div>\n<\/div>\n<p>Most of the code to retrieve folder information is the same as in TREE.PS1. What&#8217;s new is that I first create the root node in my tree view by creating a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.treenode_members.aspx\" target=\"_blank\">System.Windows.Forms.TreeNode<\/a> object.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><span style=\"color: #008000\">#write the tree root<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$leaf=(<span style=\"color: #006080\">\"{0} ({1} files {2} KB)\"<\/span> -f $path,$count,(<span style=\"color: #006080\">\"{0:N2}\"<\/span> -f ($size\/1KB)))<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$root = New-Object System.Windows.Forms.TreeNode<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$root.text = $leaf<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$root.Name = $path<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$treeView1.Nodes.Add($root) | Out-Null<\/pre>\n<\/div>\n<\/div>\n<p>The Text property is what gets displayed in the form.I don&#8217;t really need the Name property but I felt I should show it anyway. This node object is then added to the TreeView control&#8217;s Nodes collection. Now I have to get build the child nodes by calling my Get-Subfolder function.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><span style=\"color: #008000\">#enumerate child folders<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">Get-SubFolder -path $path -parent $root<\/pre>\n<\/div>\n<\/div>\n<p>This function is also basically unchanged from Tree.ps1 so I won&#8217;t go into the details. One difference though is that I pass the parent Node object as a parameter. This is so that when I get my folder information I can create a new node object and add it to the parent node&#8217;s Nodes collection.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$leaf=(<span style=\"color: #006080\">\"{0} ({1} files {2} KB)\"<\/span> -f ($subdir.name,$subcount,(<span style=\"color: #006080\">\"{0:N2}\"<\/span> -f ($subsize\/1KB))))<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\u00a0<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">node = New-Object System.Windows.Forms.TreeNode<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">node.Text=$leaf<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">node.name=$subdir.name<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><span style=\"color: #008000\"># Write-Host (\"Adding {0} to {1}\" -f $node.name,$parent.name)<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">$parent.nodes.add($node) | Out-Null<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\u00a0<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">Get-SubFolder  -path $subdir.fullname -parent $node<\/pre>\n<\/div>\n<\/div>\n<p>After adding the node I recursively call the Get-Subfolders function again. The last step in the function is to check if there are any subfolders or files within the parent node. If there are no folders or the subfolder size is 0, then I&#8217;ll display the parent node text, using the ForeColor property (or I could have used the BackColor property), to a different color.<\/p>\n<div style=\"line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;\">\n<div style=\"line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\"><span style=\"color: #0000ff\">if<\/span> ($parent.Nodes.count <span style=\"color: #cc6633\">-eq<\/span> 0 -and $subsize <span style=\"color: #cc6633\">-eq<\/span> 0)<\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">  {<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      <span style=\"color: #008000\">#empty directory so change font color<\/span><\/pre>\n<pre style=\"line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">      $parent.ForeColor=[System.Drawing.Color]::FromArgb(255,192,0,192)<\/pre>\n<pre style=\"line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;\">  }<\/pre>\n<\/div>\n<\/div>\n<p>This gives me a nice visual clue for empty directories. You might want to display a node say in red if the size exceeds a certain value.<\/p>\n<p>There is much more that you can do with the TreeView and TreeNode objects but hopefully this will get you started. If you need a copy of PrimalForms, you can download it for free from <a title=\"http:\/\/www.primaltools.com\/communitytools\/\" href=\"http:\/\/www.primaltools.com\/communitytools\/\">http:\/\/www.primaltools.com\/communitytools\/<\/a>.<\/p>\n<div id=\"scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:3293cedd-b9d6-4670-9817-5cebe46f5a2a\" class=\"wlWriterSmartContent\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">\n<p>Download an updated zip file with the Primalform form and PowerShell script <a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/06\/treedemo.zip\" target=\"_blank\">here.<\/a><\/div>\n<p>If you need help with the script or your own PowerShell project, please drop by the forums at ScriptingAnswers.com.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago I posted a PowerShell script that created a directory tree, like the TREE command from the CMD shell. Then while testing something new in PrimalForms, I realized I had a literal form object, a tree view, that I could use. So I put together a short script that creates a graphical tree for a given directory, along with the file counts and sizes from my original scripts.  As a bonus, because I now had a graphical interface I could do things such as display empty folders in a different color. The script not only gives you a handy tool but also serves as a demonstration on how to use a TreeView control.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[28,314,57,483,490,327],"class_list":["post-1340","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-powershell","tag-primalforms","tag-scripting","tag-tree","tag-treeview","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=1340"}],"version-history":[{"count":1,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions"}],"predecessor-version":[{"id":1520,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions\/1520"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=1340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=1340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=1340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}