{"id":7786,"date":"2020-10-19T12:48:32","date_gmt":"2020-10-19T16:48:32","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7786"},"modified":"2020-10-19T12:48:37","modified_gmt":"2020-10-19T16:48:37","slug":"open-up-wide-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/","title":{"rendered":"Open Up Wide with PowerShell"},"content":{"rendered":"\n<p>A few weeks ago, an Iron Scripter PowerShell scripting challenge was posted. <a href=\"https:\/\/ironscripter.us\/a-wide-open-powershell-challenge\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">The challenge involved wide directory listings<\/a>. Which always makes me think \"open wide\", which leads me to <a href=\"https:\/\/youtu.be\/dBogxn5ObgA\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\"Open Up Wide\"<\/a> by Chase. (I used to play trumpet and Chase was THE band back in the day). Anyway,  solving the challenge most likely involves a combination of Get-ChildItem and Format-Wide. Here's what I came up with.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Stand-Alone Function<\/h2>\n\n\n\n<p>My first solution takes the form of a stand-alone function. Most of the function's parameters are the same as Get-ChildItem. But I also provide a parameter to let the user specify what data to display in the [] portion of the display. Here's the complete function, then I'll point out a few things.<\/p>\n\n\n\n<pre title=\"Show-DirectoryInfo\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Show-DirectoryInfo {\n    #this version writes formatted data to the pipeline\n    [cmdletbinding()]\n    [alias(\"sw\")]\n    Param(\n        [Parameter(Position = 0,HelpMessage = \"Enter a file system path\")]\n        [ValidateScript({( Test-Path $_ ) -AND ((Get-Item $_).psprovider.name -eq \"FileSystem\")})]\n        [string]$Path = \".\",\n        [Parameter(Position = 1,HelpMessage = \"What detail do you want to see? Size or Count of files?\")]\n        [ValidateSet(\"Size\", \"Count\")]\n        [string]$Detail = \"Count\",\n        [switch]$Recurse,\n        [Int32]$Depth\n    )\n    DynamicParam {\n        if ($Detail -eq \"Size\") {\n            #define a parameter attribute object\n            $attributes = New-Object System.Management.Automation.ParameterAttribute\n            $attributes.HelpMessage = \"Enter a unit of measurement: KB, MB, GB Bytes.\"\n\n            #define a collection for attributes\n            $attributeCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]\n            $attributeCollection.Add($attributes)\n\n            #define an alias\n            $alias = New-Object System.Management.Automation.AliasAttribute -ArgumentList \"as\"\n            $attributeCollection.Add($alias)\n\n            #add a validateion set\n            $set = New-Object -type System.Management.Automation.ValidateSetAttribute -ArgumentList (\"bytes\", \"KB\", \"MB\", \"GB\")\n            $attributeCollection.add($set)\n\n            #define the dynamic param\n            $dynParam1 = New-Object -Type System.Management.Automation.RuntimeDefinedParameter(\"Unit\", [string], $attributeCollection)\n            $dynParam1.Value = \"Bytes\"\n\n            #create array of dynamic parameters\n            $paramDictionary = New-Object -Type System.Management.Automation.RuntimeDefinedParameterDictionary\n            $paramDictionary.Add(\"Unit\", $dynParam1)\n            #use the array\n            return $paramDictionary\n\n        } #if\n    } #dynamic parameter\n\n    Begin {\n        Write-Verbose \"Starting $($myinvocation.MyCommand)\"\n\n        #set a default size unit\n        if ($Detail -eq 'Size' -AND (-not $PSBoundParameters.ContainsKey(\"unit\"))) {\n            $PSBoundParameters.Add(\"Unit\", \"bytes\")\n        }\n        #these internal helper functions could be combined but I'll keep them\n        #separate for the sake of clarity.\n        function _getCount {\n            [cmdletbinding()]\n            Param([string]$Path)\n            (Get-ChildItem -Path $path -File).count\n        }\n\n        function _getSize {\n            [cmdletbinding()]\n            Param([string]$Path, [string]$Unit)\n            $sum = (Get-ChildItem $path -File | Measure-Object -Sum -Property length).sum\n            #write-verbose \"detected $unit\"\n            Switch ($Unit) {\n                \"KB\" { \"$([math]::round($sum\/1KB,2))KB\" }\n                \"MB\" { \"$([math]::round($sum\/1MB,2))MB\" }\n                \"GB\" { \"$([math]::round($sum\/1GB,2))GB\" }\n                Default { $sum }\n            }\n        }\n        Write-Verbose \"PSBoundParameters\"\n        Write-Verbose ($PSBoundParameters | Out-String)\n\n        #build a hashtable of parameters to splat to Get-ChildItem\n        $gciParams = @{\n            Path = $Path\n            Directory = $True\n        }\n        if ($PSBoundParameters[\"Depth\"]) {\n            $gciParams.Add(\"Depth\", $PSBoundParameters[\"Depth\"])\n        }\n        if ($PSBoundParameters[\"Recurse\"]) {\n            $gciParams.Add(\"Recurse\", $PSBoundParameters[\"Recurse\"])\n        }\n    } #begin\n    Process {\n        Write-Verbose \"Processing $(Convert-Path $Path)\"\n\n        $directories = Get-ChildItem @gciParams\n\n        #this code could be consolidated using techniques like splatting. This version emphasizes clarity.\n        if ($Detail -eq \"count\") {\n            Write-Verbose \"Getting file count\"\n            if ($Recurse) {\n                $directories | Get-ChildItem -Recurse -Directory | Format-Wide -Property { \"$($_.name) [$( _getCount $_.fullname)]\" } -AutoSize -GroupBy @{Name = \"Path\"; Expression = { $_.Parent }}\n            }\n            else {\n                $directories | Format-Wide -Property { \"$($_.name) [$( _getCount $_.fullname)]\" } -AutoSize -GroupBy @{Name=\"Path\";Expression={$_.Parent}}\n            }\n        }\n        else {\n            Write-Verbose \"Getting file size in $($PSBoundParameters['Unit']) units\"\n            if ($Recurse) {\n                $directories | Get-ChildItem -Recurse -Directory | Format-Wide -Property { \"$($_.name) [$( _getsize -Path $_.fullname -unit $($PSBoundParameters['Unit']))]\" } -AutoSize -GroupBy @{Name = \"Path\"; Expression = { $_.Parent }}\n            }\n            else {\n                $directories | Format-Wide -Property { \"$($_.name) [$( _getsize -path $_.fullname -unit $($PSBoundParameters['Unit']))]\" } -AutoSize -GroupBy @{Name = \"Path\"; Expression = { $_.Parent }}\n            }\n        }\n    } #Process\n\n    End {\n        Write-Verbose \"Ending $($myinvocation.MyCommand)\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>My function includes code to address some of the challenge's bonus elements. First, I'm using parameter validation to ensure that the path exists and it is a FileSystem path.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[Parameter(Position = 0,HelpMessage = \"Enter a file system path\")]\n[ValidateScript({( Test-Path $_ ) -AND ((Get-Item $_).psprovider.name -eq \"FileSystem\")})]\n[string]$Path = \".\",<\/code><\/pre>\n\n\n\n<p>I started out with 2 ValidateScript settings, but decided to combine them. The Detail parameter is defined with a ValidateSet attribute.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[Parameter(Position = 1,HelpMessage = \"What detail do you want to see? Size or Count of files?\")]\n[ValidateSet(\"Size\", \"Count\")]\n[string]$Detail = \"Count\",<\/code><\/pre>\n\n\n\n<p>Now for the fun part. I wanted a way to let the user format the total file size, i.e. in KB , if they wanted. But this only needs to happen if the user elects to use the Size value for the Detail parameter. I opted to use a Dynamic Parameter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">DynamicParam {\n    if ($Detail -eq \"Size\") {\n        #define a parameter attribute object\n        $attributes = New-Object System.Management.Automation.ParameterAttribute\n        $attributes.HelpMessage = \"Enter a unit of measurement: KB, MB, GB Bytes.\"\n\n        #define a collection for attributes\n        $attributeCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]\n        $attributeCollection.Add($attributes)\n\n        #define an alias\n        $alias = New-Object System.Management.Automation.AliasAttribute -ArgumentList \"as\"\n        $attributeCollection.Add($alias)\n\n        #add a validateion set\n        $set = New-Object -type System.Management.Automation.ValidateSetAttribute -ArgumentList (\"bytes\", \"KB\", \"MB\", \"GB\")\n        $attributeCollection.add($set)\n\n        #define the dynamic param\n        $dynParam1 = New-Object -Type System.Management.Automation.RuntimeDefinedParameter(\"Unit\", [string], $attributeCollection)\n        $dynParam1.Value = \"Bytes\"\n\n        #create array of dynamic parameters\n        $paramDictionary = New-Object -Type System.Management.Automation.RuntimeDefinedParameterDictionary\n        $paramDictionary.Add(\"Unit\", $dynParam1)\n        #use the array\n        return $paramDictionary\n\n    } #if\n} #dynamic parameter<\/code><\/pre>\n\n\n\n<p>This parameter only exists if the Detail parameter is \"Size\". The code creates a dynamic parameter as <strong>Unit <\/strong>with an alias of <em>As<\/em>. It also defines a validation set.<\/p>\n\n\n\n<p>The main part of the function calls Get-ChildItem with the proper parameters and then formats the results using Format-Wide with auto sizing and grouping on the Parent path.<\/p>\n\n\n\n<p>Here's the default behavior.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"226\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1024x226.png\" alt=\"\" class=\"wp-image-7788\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1024x226.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-300x66.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-768x169.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1536x338.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-850x187.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png 1929w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Or using the dynamic parameter.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"263\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2-1024x263.png\" alt=\"\" class=\"wp-image-7789\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2-1024x263.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2-300x77.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2-768x197.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2-1536x394.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2-850x218.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-2.png 1872w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This works, but there are a number of potential drawbacks. <\/p>\n\n\n\n<p>First, the dynamic parameter is problematic. By default it doesn't show in command help.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"276\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help-1024x276.png\" alt=\"\" class=\"wp-image-7790\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help-1024x276.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help-300x81.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help-768x207.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help-1536x414.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help-850x229.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-help.png 1961w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Although PSReadline and tab-completion should detect it. I'm not a big fan of dynamic parameters, especially when there are other options. In this function, I could have defined multiple parameter sets. One for Count and one for Size. If I were to go forward with this function, that is a change I would make. I kept the dynamic parameter in this example because I get asked about it often and here's a nice working demonstration.<\/p>\n\n\n\n<p>The other issue with this approach is that formatting is included in the function. That means the output of this function is a format wide directive, not a \"real\" object. They only thing I can do is look at the output or pipe it to Out-Printer or Out-File. You almost never want to to include Format commands in your function. That's one of the reasons I used <strong>Show<\/strong> as the command verb. I'm not <em>getting <\/em>something, I'm <em>showing<\/em> it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using a PowerShell Class<\/h2>\n\n\n\n<p>Since I'm writing a function, it needs to write an object to the pipeline. I can pipe the function output to Format-Wide to get the desired result. I could have used Select-Object or the [pscustomobject] type in my function but I opted for a PowerShell class definition.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Class DirectoryStat {\n    [string]$Name\n    [string]$Path\n    [int64]$FileCount\n    [int64]$FileSize\n    [string]$Parent\n    [string]$Computername = [System.Environment]::MachineName\n} #close class definition<\/code><\/pre>\n\n\n\n<p>The class doesn't have any methods or special constructors. I then wrote a function to use this class.<\/p>\n\n\n\n<pre title=\"Get-DirectoryInfo\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-DirectoryInfo {\n    [cmdletbinding()]\n    [alias(\"dw\")]\n    [OutputType(\"DirectoryStat\")]\n    Param(\n        [Parameter(Position = 0)]\n        [ValidateScript( { (Test-Path $_ ) -AND ((Get-Item $_).psprovider.name -eq \"FileSystem\") })]\n        [string]$Path = \".\",\n        [switch]$Recurse,\n        [int32]$Depth\n    )\n\n    Begin {\n        Write-Verbose \"Starting $($myinvocation.MyCommand)\"\n\n        #initialize a collection to hold the results\n        $data = [System.Collections.Generic.list[object]]::new()\n\n        function _newDirectoryStat {\n            [CmdletBinding()]\n            Param(\n                [Parameter(ValueFromPipelineByPropertyName, Mandatory)]\n                [string]$PSPath\n            )\n\n            Begin {}\n            Process {\n                $path = Convert-Path $PSPath\n                $name = Split-Path -Path $Path -Leaf\n                $stat = Get-ChildItem -Path $path -File | Measure-Object -Property Length -Sum\n\n                $ds = [DirectoryStat]::New()\n                $ds.Name = $name\n                $ds.Path = $Path\n                $ds.FileCount = $stat.Count\n                $ds.FileSize = $stat.Sum\n                $ds.Parent = (Get-Item -Path $path).Parent.FullName\n                $ds\n            }\n            end {}\n        }\n\n        Write-Verbose \"PSBoundParameters\"\n        Write-Verbose ($PSBoundParameters | Out-String)\n        #build a hashtable of parameters to splat to Get-ChildItem\n        $gciParams = @{\n            Path      = $Path\n            Directory = $True\n        }\n        if ($PSBoundParameters[\"Depth\"]) {\n            $gciParams.Add(\"Depth\", $PSBoundParameters[\"Depth\"])\n        }\n        if ($PSBoundParameters[\"Recurse\"]) {\n            $gciParams.Add(\"Recurse\", $PSBoundParameters[\"Recurse\"])\n        }\n\n    } #begin\n    Process {\n        Write-Verbose \"Processing $(Convert-Path $Path)\"\n\n        $data.Add((Get-ChildItem @gciParams | _newDirectoryStat))\n\n    } #Process\n\n    End {\n        #pre-sort the data\n        $data | Sort-Object -Property Parent, Name\n        Write-Verbose \"Ending $($myinvocation.MyCommand)\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>As you can see, the function writes an object to the pipeline which I can format anyway I need.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-1024x606.png\" alt=\"\" class=\"wp-image-7791\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-1024x606.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-300x178.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-768x454.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-1536x909.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-2048x1212.png 2048w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-1-850x503.png 850w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"606\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-1024x606.png\" alt=\"\" class=\"wp-image-7793\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-1024x606.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-300x178.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-768x454.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-1536x909.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-2048x1212.png 2048w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-2-1-850x503.png 850w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The challenge was on displaying results in a wide format. As you can see, that is certainly possible. But to make this easier, since I'm using a custom object, I can create a custom format file. I used <a href=\"https:\/\/github.com\/jdhitsolutions\/PSScriptTools\/blob\/master\/docs\/New-PSFormatXML.md\" target=\"_blank\" rel=\"noreferrer noopener\">New-PSFormatXML<\/a> from the PSScriptTools module to create a default view and then a second named view.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">dw | New-PSFormatXML -Path .\\directorystat.format.ps1xml -Properties Name -GroupBy Parent -FormatType Wide\ndw | New-PSFormatXML -Path .\\directorystat.format.ps1xml -Properties Name -GroupBy Parent -FormatType Wide -append -ViewName sizekb<\/code><\/pre>\n\n\n\n<p>My function has an alias of <em>dw<\/em>. I modified the file with scriptblocks so that the default view is a wide entry with a custom display showing the directory name and the file count in brackets. I also updated the sizeKB view to show the file size formatted in KB inside the square brackets. From this I simply copied, pasted and edited to get additional views.<\/p>\n\n\n\n<p>All I need to do is load the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Update-FormatData .\\directorystat.format.ps1xml<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"345\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-format-1024x345.png\" alt=\"\" class=\"wp-image-7795\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-format-1024x345.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-format-300x101.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-format-768x259.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-format-850x286.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-format.png 1455w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><a href=\"https:\/\/github.com\/jdhitsolutions\/PSScriptTools\/blob\/master\/docs\/Get-FormatView.md\" target=\"_blank\" rel=\"noreferrer noopener\">Get-FormatView<\/a> is also part of the PSScriptTools module. With this format file, I now have a default view with file count values.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"236\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default-1024x236.png\" alt=\"\" class=\"wp-image-7796\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default-1024x236.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default-300x69.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default-768x177.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default-1536x354.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default-850x196.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-default.png 1938w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Or I can name additional wide views.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"370\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb-1024x370.png\" alt=\"\" class=\"wp-image-7797\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb-1024x370.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb-300x108.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb-768x278.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb-1536x555.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb-850x307.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/dw-kb.png 1624w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As you can see, I added ANSI-escape sequences in the ps1xml file. This should work in Windows PowerShell and PowerShell 7.<\/p>\n\n\n\n<pre title=\"directorystat.format.ps1xml\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;!--\nformat type data generated 10\/07\/2020 12:20:03 by PROSPERO\\Jeff\nFile created with New-PSFormatXML from the PSScriptTools module\nwhich can be installed from the PowerShell Gallery\n-->\n&lt;Configuration>\n  &lt;ViewDefinitions>\n    &lt;View>\n      &lt;!--Created 10\/07\/2020 12:20:03 by PROSPERO\\Jeff-->\n      &lt;Name>default&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>DirectoryStat&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;GroupBy>\n        &lt;ScriptBlock>\"$([char]0x1b)[1;93m$($_.Parent)$([char]0x1b)[0m\"&lt;\/ScriptBlock>\n        &lt;Label>Path&lt;\/Label>\n      &lt;\/GroupBy>\n      &lt;WideControl>\n      &lt;AutoSize \/>\n        &lt;WideEntries>\n          &lt;WideEntry>\n            &lt;WideItem>\n              &lt;ScriptBlock>\"$([char]0x1b)[92m{0}$([char]0x1b)[0m [{1}]\" -f $_.Name,$_.filecount&lt;\/ScriptBlock>\n            &lt;\/WideItem>\n          &lt;\/WideEntry>\n        &lt;\/WideEntries>\n      &lt;\/WideControl>\n    &lt;\/View>\n    &lt;View>\n      &lt;!--Created 10\/07\/2020 12:23:20 by PROSPERO\\Jeff-->\n      &lt;Name>size&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>DirectoryStat&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;GroupBy>\n       &lt;ScriptBlock>\"$([char]0x1b)[1;93m$($_.Parent)$([char]0x1b)[0m\"&lt;\/ScriptBlock>\n        &lt;Label>Path&lt;\/Label>\n      &lt;\/GroupBy>\n      &lt;WideControl>\n      &lt;AutoSize \/>\n        &lt;WideEntries>\n          &lt;WideEntry>\n            &lt;WideItem>\n              &lt;ScriptBlock>\"$([char]0x1b)[92m{0}$([char]0x1b)[0m [$([char]0x1b)[38;5;190m{1}$([char]0x1b)[0m]\" -f $_.Name,$_.filesize&lt;\/ScriptBlock>\n            &lt;\/WideItem>\n          &lt;\/WideEntry>\n        &lt;\/WideEntries>\n      &lt;\/WideControl>\n    &lt;\/View>\n    &lt;View>\n      &lt;!--Created 10\/07\/2020 12:23:20 by PROSPERO\\Jeff-->\n      &lt;Name>sizekb&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>DirectoryStat&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;GroupBy>\n        &lt;ScriptBlock>\"$([char]0x1b)[1;93m$($_.Parent)$([char]0x1b)[0m\"&lt;\/ScriptBlock>\n        &lt;Label>Path&lt;\/Label>\n      &lt;\/GroupBy>\n      &lt;WideControl>\n        &lt;WideEntries>\n          &lt;WideEntry>\n            &lt;WideItem>\n              &lt;ScriptBlock>\"$([char]0x1b)[92m{0}$([char]0x1b)[0m [$([char]0x1b)[38;5;164m{1}KB$([char]0x1b)[0m]\" -f $_.Name,([math]::Round($_.filesize\/1KB,2))&lt;\/ScriptBlock>\n            &lt;\/WideItem>\n          &lt;\/WideEntry>\n        &lt;\/WideEntries>\n      &lt;\/WideControl>\n    &lt;\/View>\n    &lt;View>\n      &lt;!--Created 10\/07\/2020 12:23:20 by PROSPERO\\Jeff-->\n      &lt;Name>sizemb&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>DirectoryStat&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;GroupBy>\n        &lt;ScriptBlock>\"$([char]0x1b)[1;93m$($_.Parent)$([char]0x1b)[0m\"&lt;\/ScriptBlock>\n        &lt;Label>Path&lt;\/Label>\n      &lt;\/GroupBy>\n      &lt;WideControl>\n        &lt;WideEntries>\n          &lt;WideEntry>\n            &lt;WideItem>\n              &lt;ScriptBlock>\"$([char]0x1b)[92m{0}$([char]0x1b)[0m [$([char]0x1b)[38;5;147m{1}MB$([char]0x1b)[0m]\" -f $_.Name,([math]::Round($_.filesize\/1mb,2))&lt;\/ScriptBlock>\n            &lt;\/WideItem>\n          &lt;\/WideEntry>\n        &lt;\/WideEntries>\n      &lt;\/WideControl>\n    &lt;\/View>\n  &lt;\/ViewDefinitions>\n&lt;\/Configuration><\/code><\/pre>\n\n\n\n<p>This is the approach I recommend when it comes to scripting with PowerShell. Have your functions write objects to the pipeline. This is your raw output. Then use the PowerShell commands to manipulate and format the data as necessary. If you know you want some default formatting, then create a format.ps1xml file.<\/p>\n\n\n\n<p>I realize some of you are still beginning to learn PowerShell and that's ok. That's the point behind the Iron Scripter challenges -- to test and extend your skills. I hope you'll give some of the other challenges a spin.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago, an Iron Scripter PowerShell scripting challenge was posted. The challenge involved wide directory listings. Which always makes me think &#8220;open wide&#8221;, which leads me to &#8220;Open Up Wide&#8221; by Chase. (I used to play trumpet and Chase was THE band back in the day). Anyway, solving the challenge most likely involves&#8230;<\/p>\n","protected":false},"author":1,"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,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Open Up Wide with #PowerShell","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[516,634,618,534],"class_list":["post-7786","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-classes","tag-format-wide","tag-iron-scripter","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Open Up Wide with PowerShell &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Open Up Wide with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"A few weeks ago, an Iron Scripter PowerShell scripting challenge was posted. The challenge involved wide directory listings. Which always makes me think &quot;open wide&quot;, which leads me to &quot;Open Up Wide&quot; by Chase. (I used to play trumpet and Chase was THE band back in the day). Anyway, solving the challenge most likely involves...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-19T16:48:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-19T16:48:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1024x226.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Open Up Wide with PowerShell\",\"datePublished\":\"2020-10-19T16:48:32+00:00\",\"dateModified\":\"2020-10-19T16:48:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/\"},\"wordCount\":851,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/sw-1-1024x226.png\",\"keywords\":[\"Classes\",\"Format-Wide\",\"Iron Scripter\",\"PowerShell\"],\"articleSection\":[\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/\",\"name\":\"Open Up Wide with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/sw-1-1024x226.png\",\"datePublished\":\"2020-10-19T16:48:32+00:00\",\"dateModified\":\"2020-10-19T16:48:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/sw-1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/sw-1.png\",\"width\":1929,\"height\":425},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/7786\\\/open-up-wide-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Scripting\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/scripting\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Open Up Wide with PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Open Up Wide with PowerShell &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Open Up Wide with PowerShell &#8226; The Lonely Administrator","og_description":"A few weeks ago, an Iron Scripter PowerShell scripting challenge was posted. The challenge involved wide directory listings. Which always makes me think \"open wide\", which leads me to \"Open Up Wide\" by Chase. (I used to play trumpet and Chase was THE band back in the day). Anyway, solving the challenge most likely involves...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-10-19T16:48:32+00:00","article_modified_time":"2020-10-19T16:48:37+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1024x226.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Open Up Wide with PowerShell","datePublished":"2020-10-19T16:48:32+00:00","dateModified":"2020-10-19T16:48:37+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/"},"wordCount":851,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1024x226.png","keywords":["Classes","Format-Wide","Iron Scripter","PowerShell"],"articleSection":["Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/","name":"Open Up Wide with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1-1024x226.png","datePublished":"2020-10-19T16:48:32+00:00","dateModified":"2020-10-19T16:48:37+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png","width":1929,"height":425},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Scripting","item":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},{"@type":"ListItem","position":2,"name":"Open Up Wide with PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":9018,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9018\/an-iron-scripter-warm-up-solution\/","url_meta":{"origin":7786,"position":0},"title":"An Iron Scripter Warm-Up Solution","author":"Jeffery Hicks","date":"May 6, 2022","format":false,"excerpt":"We just wrapped up the 2022 edition of the PowerShell+DevOps Global Summit. It was terrific to be with passionate PowerShell professionals again. The culmination of the event is the Iron Scripter Challenge. You can learn more about this year's event and winner here. But there is more to the Iron\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8107,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8107\/scripting-challenge-meetup\/","url_meta":{"origin":7786,"position":1},"title":"Scripting Challenge Meetup","author":"Jeffery Hicks","date":"February 1, 2021","format":false,"excerpt":"As you probably know, I am the PowerShell problem master behind the challenges from the Iron Scripter site. Solving a PowerShell scripting challenge is a great way to test your skills and expand your knowledge. The final result is merely a means to an end. How you get there and\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/rubik.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":7549,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7549\/building-a-powershell-inventory\/","url_meta":{"origin":7786,"position":2},"title":"Building a PowerShell Inventory","author":"Jeffery Hicks","date":"June 16, 2020","format":false,"excerpt":"A few weeks ago, a new Iron Scripter PowerShell scripting challenge was issued. For this challenge we were asked to write some PowerShell code that we could use to inventory our PowerShell script library.\u00a0 Here's how I approached the problem, which by no means is the only way. Lines of\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/ast-results.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/ast-results.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/ast-results.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":9057,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/","url_meta":{"origin":7786,"position":3},"title":"Using PowerShell Your Way","author":"Jeffery Hicks","date":"June 6, 2022","format":false,"excerpt":"I've often told people that I spend my day in a PowerShell prompt. I run almost my entire day with PowerShell. I've shared many of the tools I use daily on Github. Today, I want to share another way I have PowerShell work the way I need it, with minimal\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":8236,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8236\/solving-another-powershell-math-challenge\/","url_meta":{"origin":7786,"position":4},"title":"Solving Another PowerShell Math Challenge","author":"Jeffery Hicks","date":"March 22, 2021","format":false,"excerpt":"Last month, the Iron Scripter Chairman posted a \"fun\" PowerShell scripting challenge. Actually, a few math-related challenges . As with all these challenges, the techniques and concepts you use to solve the challenge are more important than the result itself. Here's how I approached the problems. Problem #1 The first\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":7489,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7489\/powershell-word-play\/","url_meta":{"origin":7786,"position":5},"title":"PowerShell Word Play","author":"Jeffery Hicks","date":"May 19, 2020","format":false,"excerpt":"A few weeks ago an Iron Scripter PowerShell challenge was issued that involved playing with words and characters. Remember, the Iron Scripter challenges aren't intended to create meaningful, production worthy code. They are designed to help you learn PowerShell fundamentals and scripting techniques. This particular challenge was aimed at beginner\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=7786"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7786\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}