{"id":9057,"date":"2022-06-06T11:37:08","date_gmt":"2022-06-06T15:37:08","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=9057"},"modified":"2022-06-07T12:38:28","modified_gmt":"2022-06-07T16:38:28","slug":"using-powershell-your-way","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/","title":{"rendered":"Using PowerShell Your Way"},"content":{"rendered":"\n<p>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 effort. This specific task centers on files and folders. <\/p>\n\n\n\n<p>As you might expect, I am constantly creating, editing, and managing files. I do all of this from a PowerShell prompt. I rarely use the start menu to find a program to launch. My challenge has always been finding the files and folders I've recently been using. Get-ChildItem is naturally the PowerShell tool of choice, but I've finally gotten around to making it work the way <strong><em>I<\/em><\/strong> need.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get-ChildItem Defaults<\/h2>\n\n\n\n<p>The default behavior for Get-ChildItem has always been to sort by name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"661\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-1024x661.png\" alt=\"Get-ChildItem defaults\" class=\"wp-image-9058\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-1024x661.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-300x194.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-768x496.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-850x549.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default.png 1107w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Directories are listed first, sorted by name, and then files, also sorted by name. Often, I'm trying to remember what folder I was using, and this output doesn't make that easy for me. What I need is a sort by the LastWriteTime property. But I still want folders listed first, followed by files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a New Command<\/h2>\n\n\n\n<p>I can't use a custom format view because that won't do the sorting. In addition, I want to make this an easy process. I know I can run a PowerShell expression like this to get the desired result.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-ChildItem | Sort-Object -Property { -Not $_.psiscontainer }, LastWritetime<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"661\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted-1024x661.png\" alt=\"\" class=\"wp-image-9059\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted-1024x661.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted-300x194.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted-768x496.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted-850x549.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-sorted.png 1107w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Sort-Object is sorting pipeline input on two properties. The first is a custom property defined on-the-fly by the scriptblock. The scriptblock looks at the PSIsContainer property, a Boolean value. Files will have a value of True and folders a value of False. I want folders to display first, so I'm using the -Not operator to invert the value. After items are sorted on this property, they are sorted on the LastWriteTime. This makes my life much, much easier. But I'm lazy. I don't want to remember to type all of this, even with auto-completion via PSReadline. <\/p>\n\n\n\n<p>How about a function?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-MyFolderItem {\n    [cmdletbinding()]\n    [alias(\"dl\")]\n    Param(\n        [Parameter(Position = 0)]\n        [string]$Path,\n        [Parameter(Position = 1)]\n        [string]$Flter,\n        [switch]$File,\n        [switch]$Directory,\n        [string[]]$Exclude,\n        [string[]]$Include,\n        [switch]$Recurse\n    )\n    #Run Get-Childitem with whatever parameters are specified.\n    Get-ChildItem @psboundparameters | Sort-Object -Property { -Not $_.psiscontainer }, LastWritetime\n}<\/code><\/pre>\n\n\n\n<p>This function is nothing more than a wrapper around Get-ChildItem. My function parameters mirror those of Get-ChildItem. I'm splatting $PSBoundParameters to Get-ChildItem and then performing my sort.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png\"><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"572\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png\" alt=\"using my Get-ChildItem wrapper function\" class=\"wp-image-9060\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png 733w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl-300x234.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/a><\/figure>\n\n\n\n<p>$PSBoundParameters is an intrinsic variable. It is a specialized hashtable that contains every parameter with a value. I also added an alias to my function to make this even easier to use. I can put this function in my PowerShell profile script, and I am set.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Listing by Proxy<\/h2>\n\n\n\n<p>But there is another way I can create this command. I could make a proxy function. This is a particular type of function. Proxy functions often replace original commands. Typically, you use proxy functions to add or remove parameters or customize a command's behavior. You often see proxy functions with Just Enough Administration (JEA) deployments. But I could use a proxy function built on Get-ChildItem.<\/p>\n\n\n\n<p>The easiest way to get started is with <a href=\"http:\/\/bit.ly\/31Ty8Sm\" target=\"_blank\" rel=\"noreferrer noopener\">Copy-Command<\/a> from my PSScriptTools module.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">Copy-Command Get-Childitem -AsProxy -UseForwardHelp -IncludeDynamic<\/code><\/pre>\n\n\n\n<p>Run this command in the VS Code integrated editor, and it will load a new file into the editor.<\/p>\n\n\n\n<p>If you are building proxy functions, pay attention to your PowerShell version. I created my file in PowerShell 7. Fortunately, the parameters are unchanged in Windows PowerShell, so that I can use my proxy function in both versions. But that may always not be the case.<\/p>\n\n\n\n<p>Here's the proxy function with one addition.<\/p>\n\n\n\n<pre title=\"Get-ChildItem-Proxy.ps1\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#requires -version 5.1\n\n&lt;#\nThis is a copy of:\n\nCommandType Name          Version Source\n----------- ----          ------- ------\nCmdlet      Get-ChildItem 7.0.0.0 Microsoft.PowerShell.Management\n\nCreated: 06 June 2022\nAuthor : Jeff Hicks\n\nCreated with Copy-Command from the PSScriptTools module\nhttps:\/\/github.com\/jdhitsolutions\/PSScriptTools\n\nCopy-Command Get-Childitem -AsProxy -UseForwardHelp -IncludeDynamic\n\n#>\n\n\nFunction Get-ChildItem {\n    &lt;#\n.ForwardHelpTargetName Microsoft.PowerShell.Management\\Get-ChildItem\n.ForwardHelpCategory Cmdlet\n\n#>\n    [CmdletBinding(DefaultParameterSetName = 'Items', SupportsTransactions = $true, HelpUri = 'https:\/\/go.microsoft.com\/fwlink\/?LinkID=113308')]\n    Param(\n\n        [Parameter(ParameterSetName = 'Items', Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]\n        [string[]]$Path,\n\n        [Parameter(ParameterSetName = 'LiteralItems', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]\n        [Alias('PSPath')]\n        [string[]]$LiteralPath,\n\n        [Parameter(Position = 1)]\n        [string]$Filter,\n\n        [switch]$File,\n\n        [switch]$Directory,\n\n        [string[]]$Include,\n\n        [string[]]$Exclude,\n\n        [Alias('s')]\n        [switch]$Recurse,\n\n        [uint32]$Depth,\n\n        [switch]$Force,\n\n        [switch]$Name\n    )\n\n    Begin {\n\n        Write-Verbose \"[BEGIN  ] Starting $($MyInvocation.Mycommand)\"\n        Write-Verbose \"[BEGIN  ] Using parameter set $($PSCmdlet.ParameterSetName)\"\n        Write-Verbose ($PSBoundParameters | Out-String)\n\n        try {\n            $outBuffer = $null\n            if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) {\n                $PSBoundParameters['OutBuffer'] = 1\n            }\n            $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet)\n            #sort the output with directories first and then sorted by last write time\n            $scriptCmd = { &amp; $wrappedCmd @PSBoundParameters | Sort-Object -Property { -Not $_.psiscontainer }, LastWritetime }\n            $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)\n            $steppablePipeline.Begin($PSCmdlet)\n        }\n        catch {\n            throw\n        }\n\n    } #begin\n\n    Process {\n\n        try {\n            $steppablePipeline.Process($_)\n        }\n        catch {\n            throw\n        }\n\n\n    } #process\n\n    End {\n\n        try {\n            $steppablePipeline.End()\n        }\n        catch {\n            throw\n        }\n        Write-Verbose \"[END    ] Ending $($MyInvocation.Mycommand)\"\n\n    } #end\n\n} #end function Get-ChildItem<\/code><\/pre>\n\n\n\n<p>The proxy function is also \"wrapping\" Get-ChildItem.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"> $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet)<\/code><\/pre>\n\n\n\n<p>All I'm doing is sorting the output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$scriptCmd = { &amp; $wrappedCmd @PSBoundParameters | Sort-Object -Property { -Not $_.psiscontainer }, LastWritetime }<\/code><\/pre>\n\n\n\n<p>All I have to do is dot-source the proxy function script. From now on, whenever I run Get-Childitem, it will use my proxied version.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"661\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied-1024x661.png\" alt=\"\" class=\"wp-image-9061\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied-1024x661.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied-300x194.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied-768x496.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied-850x549.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-proxied.png 1107w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>In my proxy function, I haven't changed anything about how the underlying command, Get-ChildItem, runs. All I've done is add sorting. I can continue to use Get-Childitem as I always have. But now, in the file system, I get the desired output.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Get-Command confirms I am running a custom version of Get-Childitem.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-command.png\"><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"117\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-command.png\" alt=\"\" class=\"wp-image-9062\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-command.png 781w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-command-300x45.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-command-768x115.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/a><\/figure>\n\n\n\n<p>To be honest, I'm not sure which approach I'll use long-term. For now, I'm loading my wrapper function with the <em>dl<\/em> alias and the proxy function in my PowerShell profile script. I'll have to see if there are any limitations to the proxy function that I haven't considered yet.<\/p>\n\n\n\n<p>If you need to bend a PowerShell command to meet <em>your<\/em> needs, I hope my examples can serve as templates for solutions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Update<\/h2>\n\n\n\n<p>After using my proxy function for a bit, I realized I neglected to include the dynamic parameters -File and -Directory. I updated the code samples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve often told people that I spend my day in a PowerShell prompt. I run almost my entire day with PowerShell. I&#8217;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 effort. This specific task centers&#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: Using #PowerShell Commands *Your* Way","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":[4,8],"tags":[224,534,475,540],"class_list":["post-9057","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-function","tag-powershell","tag-proxy-function","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using PowerShell Your Way &#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\/powershell\/9057\/using-powershell-your-way\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using PowerShell Your Way &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I&#039;ve often told people that I spend my day in a PowerShell prompt. I run almost my entire day with PowerShell. I&#039;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 effort. This specific task centers...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-06T15:37:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-07T16:38:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-1024x661.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Using PowerShell Your Way\",\"datePublished\":\"2022-06-06T15:37:08+00:00\",\"dateModified\":\"2022-06-07T16:38:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/\"},\"wordCount\":775,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/get-childitem-default-1024x661.png\",\"keywords\":[\"Function\",\"PowerShell\",\"Proxy function\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/\",\"name\":\"Using PowerShell Your Way &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/get-childitem-default-1024x661.png\",\"datePublished\":\"2022-06-06T15:37:08+00:00\",\"dateModified\":\"2022-06-07T16:38:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/get-childitem-default.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/get-childitem-default.png\",\"width\":1107,\"height\":715},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9057\\\/using-powershell-your-way\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using PowerShell Your Way\"}]},{\"@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":"Using PowerShell Your Way &#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\/powershell\/9057\/using-powershell-your-way\/","og_locale":"en_US","og_type":"article","og_title":"Using PowerShell Your Way &#8226; The Lonely Administrator","og_description":"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 effort. This specific task centers...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/","og_site_name":"The Lonely Administrator","article_published_time":"2022-06-06T15:37:08+00:00","article_modified_time":"2022-06-07T16:38:28+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-1024x661.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Using PowerShell Your Way","datePublished":"2022-06-06T15:37:08+00:00","dateModified":"2022-06-07T16:38:28+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/"},"wordCount":775,"commentCount":3,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-1024x661.png","keywords":["Function","PowerShell","Proxy function","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/","name":"Using PowerShell Your Way &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default-1024x661.png","datePublished":"2022-06-06T15:37:08+00:00","dateModified":"2022-06-07T16:38:28+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/get-childitem-default.png","width":1107,"height":715},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Using PowerShell Your Way"}]},{"@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":7317,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7317\/fast-folder-sizes-with-powershell\/","url_meta":{"origin":9057,"position":0},"title":"Fast Folder Sizes with PowerShell","author":"Jeffery Hicks","date":"February 25, 2020","format":false,"excerpt":"I am always looking for ways to do things faster and easier with PowerShell. One common task that I never seem to stop needing is discovering how much disk space a given folder is consuming. Even though disk space is cheap these days, I guess I'm old-school enough to want\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\/02\/getfoldersize3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8622,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8622\/finding-modified-files-with-powershell\/","url_meta":{"origin":9057,"position":1},"title":"Finding Modified Files with PowerShell","author":"Jeffery Hicks","date":"October 14, 2021","format":false,"excerpt":"Here's another task that I seem to be constantly fiddling with using PowerShell. What files did I work on yesterday? Or what files were modified in the last 48 hours? Obviously, Get-ChildItem is going to be the primary command. It is simple enough to get files based on an extension\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\/10\/extension-report.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/extension-report.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/extension-report.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3014,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","url_meta":{"origin":9057,"position":2},"title":"Getting Top Level Folder Report in PowerShell","author":"Jeffery Hicks","date":"May 9, 2013","format":false,"excerpt":"One of the sessions I presented recently at TechDays San Francisco was on file share management with PowerShell. One of the scripts I demonstrated was for a function to get information for top level folders. This is the type of thing that could be handy to run say against the\u2026","rel":"","context":"In &quot;Conferences&quot;","block_context":{"text":"Conferences","link":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},"img":{"alt_text":"foldersize","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png?resize=525%2C300 1.5x"},"classes":[]},{"id":3551,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","url_meta":{"origin":9057,"position":3},"title":"PowerShell Clean Up Tools","author":"Jeffery Hicks","date":"November 11, 2013","format":false,"excerpt":"A few years ago I think I posted some PowerShell clean up tools. These were functions designed to help clear out old files, especially for folders like TEMP. Recently I decided to upgrade them to at least PowerShell 3.0 to take advantage of v3 cmdlets and features. I use these\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"021913_2047_WordTest1.png","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2673,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2673\/friday-fun-edit-recent-file\/","url_meta":{"origin":9057,"position":4},"title":"Friday Fun: Edit Recent File","author":"Jeffery Hicks","date":"January 4, 2013","format":false,"excerpt":"As you might imagine I work on a lot of PowerShell projects at the same time. Sometimes I'll start something at the beginning of the week and then need to come back to it at the end of the week. The problem is that I can't always remembered what I\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"Edit-RecentFile","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/Edit-RecentFile-300x209.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6629,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6629\/extending-powershell-and-docker-containers\/","url_meta":{"origin":9057,"position":5},"title":"Extending PowerShell and Docker Containers","author":"Jeffery Hicks","date":"April 2, 2019","format":false,"excerpt":"I've been continuing to tinker with my PowerShell command for getting information about Docker containers. The Docker CLI is fine, but it is very difficult to work with the output or do much with it. That's why I prefer to have objects in a PowerShell pipeline. One of the Docker\u2026","rel":"","context":"In &quot;Docker&quot;","block_context":{"text":"Docker","link":"https:\/\/jdhitsolutions.com\/blog\/category\/docker\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/04\/image_thumb-6.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/04\/image_thumb-6.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/04\/image_thumb-6.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/04\/image_thumb-6.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9057","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=9057"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9057\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}