{"id":6478,"date":"2019-01-30T10:25:30","date_gmt":"2019-01-30T15:25:30","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=6478"},"modified":"2019-01-31T09:37:07","modified_gmt":"2019-01-31T14:37:07","slug":"powershell-scripting-getting-git-size-retooled","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","title":{"rendered":"Getting Git Size with PowerShell Retooled"},"content":{"rendered":"<p>A few days ago I wrote about my experiences in designing <a title=\"Read the original article in case you missed it\" href=\"https:\/\/jdhitsolutions.com\/blog\/?p=6465\" target=\"_blank\" rel=\"blank noopener\">a PowerShell function that reports on the size<\/a> of the hidden .git folder. In that version of the function I decided to include a parameter that would permit the user to get the size pre-formatted as either KB, MB or GB. I thought long and hard about it as this really is not the best design pattern.\u00a0 Still, I'm not the only one who likes the ability to get values formatted into a more user-friendly form. So let me show you a revision that I think better adheres to PowerShell scripting best practices, yet also provides the flexibility of data formatting.<\/p>\n<p><!--more--><\/p>\n<h2>Extending a PowerShell Object<\/h2>\n<p>One of the things I appreciate about PowerShell is how easy it is to extend or modify an object type. This is because PowerShell has an extensible type system. Using the <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113421\" target=\"_blank\" rel=\"noopener\">Update-TypeData<\/a> cmdlet, it is very easy to add new properties to an object type. That is the approach I decided to take. I decided to keep my \"base\" object very simple and show the directory size in bytes. This means I removed all the code around the -As parameter.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">#get the total size of all files in the .git folder\n$stat = Get-Childitem -path $git -Recurse -File | Measure-Object -Property length -sum\n\n#create the output\n$obj = [PSCustomObject]@{\n    Path  = $full\n    Files = $stat.count\n    Size  = $stat.sum\n} #customobject\n<\/pre>\n<p>In order to extend a type you need to know the typename. When creating a PSCustomobject as I'm doing here, this will require a few extra steps to define an additional typename for the custom object. This is typically done with code like this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">#insert a new typename\n$obj.psobject.typenames.insert(0, \"gitSize\")\n#write object to the pipeline\n$obj\n<\/pre>\n<blockquote>\n<h3>Update<\/h3>\n<p>Thanks to a comment from Chris Warwick, there is an even better way to insert a type name that was introduced in PowerShell at some point and I missed it. Define a property called PSTypeName in the object itself.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$obj = [PSCustomObject]@{\n    PSTypeName = \"gitSize\"\n    Path       = $full\n    Files      = $stat.count\n    Size       = $stat.sum\n} #customobject\n<\/pre>\n<p>It won't show in the object's output but it will be used for the typename. You can verify it by piping the object to Get-Member.<\/p><\/blockquote>\n<p>I could also have created a PowerShell class which would have baked in the typename from the beginning. But that is a bit more complicated than I what to get into here. Now for the fun stuff.<\/p>\n<h2>Exploiting Update-TypeData<\/h2>\n<p>My function will now write an object to the pipeline with a typename of gitSize. I decided that all of the other properties I might want to see were completely optional. To accomplish this I am going to use the Update-TypeData command\u00a0 outside of the function. Since I would need to dot source the script file with the function anyway, I added these lines after the function definition.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Update-TypeData -TypeName gitSize -MemberType ScriptProperty -MemberName SizeKB -Value {$this.size \/ 1kb} -force\nUpdate-TypeData -TypeName gitSize -MemberType ScriptProperty -MemberName SizeMB -Value {$this.size \/ 1mb} -force\nUpdate-TypeData -TypeName gitSize -MemberType ScriptProperty -MemberName SizeGB -Value {$this.size \/ 1gb} -force\nUpdate-TypeData -TypeName gitSize -MemberType NoteProperty -MemberName Computername -Value $env:COMPUTERNAME -force\nUpdate-TypeData -TypeName gitSize -MemberType ScriptProperty -MemberName Date -Value {Get-Date} -force\nUpdate-TypeData -TypeName gitSize -MemberType ScriptProperty -MemberName Name -Value {Split-Path -path $this.path -leaf} -force\n<\/pre>\n<p>I also added a few other properties I had been thinking about like Computername and Date. Yes, I could have defined many of these as part of the custom object in which case I would have used code like this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$obj = [PSCustomObject]@{\n    Path  = $full\n    Files = $stat.count\n    Size  = $stat.sum\n    SizeKB = $stat.sum\/1kb\n    Computername = $env:computername\n} #customobject\n<\/pre>\n<p>Regardless, I knew that by default I only wanted to see the path, number of files and size in bytes.\u00a0 As things currently stand, when I run my function I'll get an object that displays everything. The solution is to use Update-TypeData and define a default set of properties.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">#set default properties\nUpdate-TypeData -TypeName gitSize -DefaultDisplayPropertySet \"Path\", \"Files\", \"Size\" -Force\n<\/pre>\n<p>When I run the function, which will write a gitSize object to the pipeline, I'll get the defaults.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image-27.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Revised Get-GitSize with defined default properties\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.png\" alt=\"Revised Get-GitSize with defined default properties\" width=\"759\" height=\"182\" border=\"0\" \/><\/a><\/p>\n<p>But all of the properties are there if I want them.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image-28.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Viewing extended object properties\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-28.png\" alt=\"Viewing extended object properties\" width=\"1028\" height=\"541\" border=\"0\" \/><\/a><\/p>\n<h2>The Extended Function<\/h2>\n<p>I've left the original function up on Github. This version can be found <a title=\"check out the new version on Github\" href=\"https:\/\/gist.github.com\/jdhitsolutions\/4b2f0acabf7bd69ac7e9c590273f36b2\" target=\"_blank\" rel=\"blank noopener\">here<\/a>.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/jdhitsolutions\/4b2f0acabf7bd69ac7e9c590273f36b2.js\"><\/script><\/p>\n<p>As before, you will need to save the file locally and dot source it into your PowerShell session. Now, I have some flexibility. I can either get the default output as I showed earlier or I can run code like this to utilize the additional properties.<\/p>\n<h2><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image-29.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Getting git size with PowerShell and additional properties\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png\" alt=\"Getting git size with PowerShell and additional properties\" width=\"1028\" height=\"625\" border=\"0\" \/><\/a>\u00a0Using a PowerShell Format File<\/h2>\n<p>Another approach I thought about, but didn't pursue, would be the use of a format.ps1xml file. This too would require me to define a typename. With this approach I would have had to create a specially formatted xml file that define table or list (usually these two) views. The views could include code to dynamically display data formatted as KB or MB. This is the type of thing done with process objects that you see when you run <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113324\" target=\"_blank\" rel=\"noopener\">Get-Process<\/a>. When you run Get-Process alone, PowerShell uses a defined table view for process objects that formats values. But it doesn't change the underlying object. Creating the xml file can be a bit tedious and I didn't want to go down that rabbit hole today. There certainly may be situations where you want to take advantage of both type and format extensions and hopefully we can revisit this topic in a future article.<\/p>\n<h2>PowerShell Scripting is a Process<\/h2>\n<p>In the mean time, take a look at the code. Consider the design process I went through. I write these articles as much for teaching you concepts and techniques as I do showing you a finished product. Although if you find it helpful, that's a bonus. Embrace and enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I wrote about my experiences in designing a PowerShell function that reports on the size of the hidden .git folder. In that version of the function I decided to include a parameter that would permit the user to get the size pre-formatted as either KB, MB or GB. I thought long&#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: Getting Git Size with #PowerShell Retooled and Extended","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":[521,4],"tags":[519,534,540,439],"class_list":["post-6478","post","type-post","status-publish","format-standard","hentry","category-git","category-powershell","tag-git","tag-powershell","tag-scripting","tag-update-typedata"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Scripting &#8226; Getting Git Size with PowerShell Retooled<\/title>\n<meta name=\"description\" content=\"Improve your PowerShell scripting game by seeing how I revised my Get-GitSize function to take advantage of PowerShell&#039;s extensible type system.\" \/>\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\/6478\/powershell-scripting-getting-git-size-retooled\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Scripting &#8226; Getting Git Size with PowerShell Retooled\" \/>\n<meta property=\"og:description\" content=\"Improve your PowerShell scripting game by seeing how I revised my Get-GitSize function to take advantage of PowerShell&#039;s extensible type system.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-30T15:25:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-31T14:37:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Getting Git Size with PowerShell Retooled\",\"datePublished\":\"2019-01-30T15:25:30+00:00\",\"dateModified\":\"2019-01-31T14:37:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/\"},\"wordCount\":822,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/image_thumb-27.png\",\"keywords\":[\"Git\",\"PowerShell\",\"Scripting\",\"Update-TypeData\"],\"articleSection\":[\"Git\",\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/\",\"name\":\"PowerShell Scripting &#8226; Getting Git Size with PowerShell Retooled\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/image_thumb-27.png\",\"datePublished\":\"2019-01-30T15:25:30+00:00\",\"dateModified\":\"2019-01-31T14:37:07+00:00\",\"description\":\"Improve your PowerShell scripting game by seeing how I revised my Get-GitSize function to take advantage of PowerShell's extensible type system.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/image_thumb-27.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/image_thumb-27.png\",\"width\":759,\"height\":182},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/6478\\\/powershell-scripting-getting-git-size-retooled\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Git\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/git\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting Git Size with PowerShell Retooled\"}]},{\"@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":"PowerShell Scripting &#8226; Getting Git Size with PowerShell Retooled","description":"Improve your PowerShell scripting game by seeing how I revised my Get-GitSize function to take advantage of PowerShell's extensible type system.","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\/6478\/powershell-scripting-getting-git-size-retooled\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Scripting &#8226; Getting Git Size with PowerShell Retooled","og_description":"Improve your PowerShell scripting game by seeing how I revised my Get-GitSize function to take advantage of PowerShell's extensible type system.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","og_site_name":"The Lonely Administrator","article_published_time":"2019-01-30T15:25:30+00:00","article_modified_time":"2019-01-31T14:37:07+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Getting Git Size with PowerShell Retooled","datePublished":"2019-01-30T15:25:30+00:00","dateModified":"2019-01-31T14:37:07+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/"},"wordCount":822,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.png","keywords":["Git","PowerShell","Scripting","Update-TypeData"],"articleSection":["Git","PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","name":"PowerShell Scripting &#8226; Getting Git Size with PowerShell Retooled","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.png","datePublished":"2019-01-30T15:25:30+00:00","dateModified":"2019-01-31T14:37:07+00:00","description":"Improve your PowerShell scripting game by seeing how I revised my Get-GitSize function to take advantage of PowerShell's extensible type system.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-27.png","width":759,"height":182},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Git","item":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},{"@type":"ListItem","position":2,"name":"Getting Git Size with PowerShell Retooled"}]},{"@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":4999,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4999\/finding-git-repositories-with-powershell\/","url_meta":{"origin":6478,"position":0},"title":"Finding Git Repositories with PowerShell","author":"Jeffery Hicks","date":"May 18, 2016","format":false,"excerpt":"As part of my ongoing improvement process this year I am starting to use Git much more. Yesterday I posted an article with my PowerShell script to create a new project folder which includes creating a Git repository. My challenge has been that I don't always remember what I have\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"find git repositories with PowerShell","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":6492,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6492\/creating-more-git-powershell-tools\/","url_meta":{"origin":6478,"position":1},"title":"Creating More Git PowerShell Tools","author":"Jeffery Hicks","date":"February 1, 2019","format":false,"excerpt":"I have received a tremendous amount of interest in my recent articles on creating a git sizing tool using PowerShell. Many of you were savvy enough to realize the journey I was describing was just as important as the destination. With that in mind, I decided to revisit another PowerShell\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/02\/image_thumb-3.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5974,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5974\/get-git-configuration-with-powershell\/","url_meta":{"origin":6478,"position":2},"title":"Get Git Configuration with PowerShell","author":"Jeffery Hicks","date":"May 11, 2018","format":false,"excerpt":"A few weeks ago I was teaching a PowerShell fundamentals course. Towards the end of the week we start creating simple scripts and functions. One night after class I was thinking about giving them another example and I was working on a project using git. At some point I was\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/05\/image_thumb-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/05\/image_thumb-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/05\/image_thumb-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/05\/image_thumb-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5121,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5121\/friday-fun-find-a-git-tip-with-powershell\/","url_meta":{"origin":6478,"position":3},"title":"Friday Fun: Find a Git Tip with PowerShell","author":"Jeffery Hicks","date":"June 24, 2016","format":false,"excerpt":"Recently I published a PowerShell function that I use to display a random Git Tip of the Day. The function relies on my clone of the Git-Tips project on GitHub. I've been keeping tabs on this project and a question was posed about creating a command line utility to search\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"finding a git tip with PowerShell","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-20.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-20.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-20.png?resize=525%2C300 1.5x"},"classes":[]},{"id":5132,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5132\/downloading-git-tips-with-powershell\/","url_meta":{"origin":6478,"position":4},"title":"Downloading Git Tips with PowerShell","author":"Jeffery Hicks","date":"June 27, 2016","format":false,"excerpt":"So I've been sharing a number of PowerShell tools I've created for working with Git, including a few for getting tips from the Git Tips project on GitHub. My initial work was based on the fact that I had a local clone of that repository and wanted to search the\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"getting all online git tips with PowerShell","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-22.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-22.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-22.png?resize=525%2C300 1.5x"},"classes":[]},{"id":5112,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5112\/creating-git-commit-messages-with-powershell\/","url_meta":{"origin":6478,"position":5},"title":"Creating Git Commit Messages with PowerShell","author":"Jeffery Hicks","date":"June 21, 2016","format":false,"excerpt":"As part of my process of learning an using Git I am trying to get in the habit of using meaningful commit messages. Sure, you can get by with a single line comment which is fine when running git log --oneline. But you can use a multi-line commit message. However,\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-19.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-19.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/06\/image_thumb-19.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6478","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=6478"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/6478\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=6478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=6478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=6478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}