{"id":1025,"date":"2010-12-06T11:50:08","date_gmt":"2010-12-06T16:50:08","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1025"},"modified":"2010-12-06T11:50:08","modified_gmt":"2010-12-06T16:50:08","slug":"out-compressedfile","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/","title":{"rendered":"Out-CompressedFile"},"content":{"rendered":"<p>I'm not sure where this idea came from, but I thought it might be nice to redirect output to a compressed text file. I know disk space is cheap these days but perhaps you're running PowerShell 2.0 on an older platform and you want to save output from a command that will generate a ton of data. Using NTFS compression might buy you a little breathing room. My function, Out-CompressedFile, can be used in place of Out-File.<!--more--><\/p>\n<p>My function doesn't have all the features of Out-File and assumes you are using most of the defaults.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\nFunction Out-CompressedFile {<\/p>\n<p>[cmdletBinding(SupportsShouldProcess=$True)]<\/p>\n<p>Param(<br \/>\n[Parameter(Position=0,Mandatory=$True,HelpMessage=\"Enter a file path and name\",<br \/>\nValueFromPipeline=$False)]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string]$FilePath,<br \/>\n[Parameter(Position=1,Mandatory=$False,ValueFromPipeline=$True)]<br \/>\n[psobject]$InputObject,<br \/>\n[switch]$Append<br \/>\n)<\/p>\n<p>Begin {<br \/>\n    Write-Verbose -Message \"$(Get-Date) Starting $($myinvocation.mycommand)\"<br \/>\n    #get file if -append was specified<br \/>\n    if ($Append -AND (Test-Path $FilePath))<br \/>\n    {<br \/>\n        Write-Verbose -Message \"$(Get-Date) Appending to $Filepath\"<br \/>\n        #get full path<br \/>\n        if (-Not $FilePath.Contains(\"\\\"))<br \/>\n        {<br \/>\n            $FilePath=(Get-Item $filePath).fullname<br \/>\n        }<br \/>\n    }<br \/>\n    elseif (-Not $Append)<br \/>\n    {<br \/>\n        #otherwise, create an empty file<br \/>\n        Write-Verbose -Message \"$(Get-Date) Creating $FilePath\"<br \/>\n        #if just a file name, then use the current working directory\"<br \/>\n        if (-not $FilePath.Contains(\"\\\"))<br \/>\n        {<br \/>\n            Write-Verbose -Message \"$(Get-Date) Using current working directory $PWD\"<br \/>\n            $FilePath=Join-Path -Path (Get-item $pwd).FullName -ChildPath $FilePath<br \/>\n        }<br \/>\n        if ($pscmdlet.ShouldProcess($filepath))<br \/>\n        {<br \/>\n            Try<br \/>\n            {<br \/>\n                #Create the file<br \/>\n                $f=[System.IO.File]::Create($filepath)<br \/>\n                $f.Close()<br \/>\n                #get the full file name<br \/>\n                $FilePath=$f.Name<br \/>\n            } #close Try<br \/>\n            Catch<br \/>\n            {<br \/>\n                Write-Warning \"Failed to create $Filepath\"<br \/>\n                Write-Error $_<br \/>\n                Exit<br \/>\n            } #close Catch<br \/>\n        } #close if should process<br \/>\n    } #close elseif not $append<br \/>\n    else<br \/>\n    {<br \/>\n        Write-Error \"Failed to find $filepath. You can only append to an existing file.\"<br \/>\n        Exit<br \/>\n    }<\/p>\n<p>     Write-Verbose -Message \"$(Get-Date) Full path is $FilePath\"<br \/>\n     #replace \\ with \\\\ for WMI<br \/>\n     $wmipath=$filePath.Replace(\"\\\",\"\\\\\")<br \/>\n     Write-Verbose -Message \"$(Get-Date) Getting $wmipath\"<br \/>\n     #check and see if file is already compressed<br \/>\n     $CIMFile=Get-WmiObject -Class CIM_DATAFILE -filter \"Name='$wmipath'\"<br \/>\n     if (-Not $CIMFile.Compressed)<br \/>\n     {<br \/>\n        #if not, compress it<br \/>\n        if ($pscmdlet.ShouldProcess(\"$Filepath\"))<br \/>\n        {<br \/>\n            Write-Verbose -Message \"$(Get-Date) Compressing $Filepath\"<br \/>\n            $rc=$CIMFile.Compress()<br \/>\n            if ($rc.ReturnValue -ne 0)<br \/>\n            {<br \/>\n                Write-Warning \"Failed to compress $Filepath. Continuing without it.\"<br \/>\n            }<br \/>\n         }<br \/>\n     } #close if not compressed<\/p>\n<p>    #initialize a variable to hold all the input<br \/>\n    Write-Verbose -Message \"$(Get-Date) Initializing data variable\"<br \/>\n    $data=@()<br \/>\n } #close Begin<\/p>\n<p>Process {<br \/>\n    Foreach ($item in $InputObject) {<br \/>\n        $data+=$item<br \/>\n    }#close Foreach <\/p>\n<p> } #close process<\/p>\n<p>End {<br \/>\n    Write-Verbose -Message \"$(Get-Date) Sending output to $FilePath\"<br \/>\n    #data will always be appended because the file always exists, even it is empty<br \/>\n    $data | Out-File -FilePath $Filepath -append<br \/>\n    Write-Verbose -Message \"$(Get-Date) Ending $($myinvocation.mycommand)\"<br \/>\n } #close End<\/p>\n<p>} #end Function<\/p>\n<p>[\/cc]<br \/>\nMy function has comment-based help but I've omitted from the listing here.<\/p>\n<p>You use the function just as you would Out-File with some subtle differences. First, if you use -Append, the function verifies the file exists. This is because I want to check and see if the file exists so I can enable compression if necessary. If you don't specify -Append, then I create an empty file.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\nTry<br \/>\n            {<br \/>\n                #Create the file<br \/>\n                $f=[System.IO.File]::Create($filepath)<br \/>\n                $f.Close()<br \/>\n                #get the full file name<br \/>\n                $FilePath=$f.Name<br \/>\n            } #close Try<br \/>\n[\/cc]<br \/>\nI also compress the file ahead of time if it is not already compressed using WMI. WMI needs \\\\ in a path for each \\ so I fix the path accordingly.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\n  #replace \\ with \\\\ for WMI<br \/>\n     $wmipath=$filePath.Replace(\"\\\",\"\\\\\")<br \/>\n     Write-Verbose -Message \"$(Get-Date) Getting $wmipath\"<br \/>\n     #check and see if file is already compressed<br \/>\n     $CIMFile=Get-WmiObject -Class CIM_DATAFILE -filter \"Name='$wmipath'\"<br \/>\n     if (-Not $CIMFile.Compressed)<br \/>\n     {<br \/>\n        #if not, compress it<br \/>\n        if ($pscmdlet.ShouldProcess(\"$Filepath\"))<br \/>\n        {<br \/>\n            Write-Verbose -Message \"$(Get-Date) Compressing $Filepath\"<br \/>\n            $rc=$CIMFile.Compress()<br \/>\n            if ($rc.ReturnValue -ne 0)<br \/>\n            {<br \/>\n                Write-Warning \"Failed to compress $Filepath. Continuing without it.\"<br \/>\n            }<br \/>\n         }<br \/>\n     } #close if not compressed<br \/>\n[\/cc]<br \/>\nOnce I have the file ready, I take all input and store it in a buffer variable. To be honest, I'm not sure what the effect will be for extremely large data sets. But I expect this to work for 99% percent of you.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\nProcess {<br \/>\n    Foreach ($item in $InputObject) {<br \/>\n        $data+=$item<br \/>\n    }#close Foreach <\/p>\n<p> } #close process<br \/>\n[\/cc]<br \/>\nThe last part of the function simply passes the data to Out-File, using the compressed file. Because the file has already been verified or created, I need to use -Append.<br \/>\n[cc lang=\"PowerShell\"]<br \/>\nEnd {<br \/>\n    Write-Verbose -Message \"$(Get-Date) Sending output to $FilePath\"<br \/>\n    #data will always be appended because the file always exists, even it is empty<br \/>\n    $data | Out-File -FilePath $Filepath -append<br \/>\n    Write-Verbose -Message \"$(Get-Date) Ending $($myinvocation.mycommand)\"<br \/>\n } #close End<br \/>\n[\/cc]<br \/>\nUse the function once it is loaded into your PowerShell session, just as you would Out-File.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-1024x619.png\" alt=\"\" title=\"out-compressedfile\" width=\"640\" height=\"386\" class=\"aligncenter size-large wp-image-1028\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-1024x619.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-300x181.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile.png 1129w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/Out-CompressedFile.txt'>Out-CompressedFile<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m not sure where this idea came from, but I thought it might be nice to redirect output to a compressed text file. I know disk space is cheap these days but perhaps you&#8217;re running PowerShell 2.0 on an older platform and you want to save output from a command that will generate a ton&#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":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[32,241,534,540],"class_list":["post-1025","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-functions","tag-out-file","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Out-CompressedFile &#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\/1025\/out-compressedfile\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Out-CompressedFile &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I&#039;m not sure where this idea came from, but I thought it might be nice to redirect output to a compressed text file. I know disk space is cheap these days but perhaps you&#039;re running PowerShell 2.0 on an older platform and you want to save output from a command that will generate a ton...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2010-12-06T16:50:08+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-1024x619.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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Out-CompressedFile\",\"datePublished\":\"2010-12-06T16:50:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/\"},\"wordCount\":746,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/12\\\/out-compressedfile-1024x619.png\",\"keywords\":[\"functions\",\"Out-File\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/\",\"name\":\"Out-CompressedFile &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/12\\\/out-compressedfile-1024x619.png\",\"datePublished\":\"2010-12-06T16:50:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/12\\\/out-compressedfile.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2010\\\/12\\\/out-compressedfile.png\",\"width\":\"1129\",\"height\":\"683\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1025\\\/out-compressedfile\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Out-CompressedFile\"}]},{\"@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":"Out-CompressedFile &#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\/1025\/out-compressedfile\/","og_locale":"en_US","og_type":"article","og_title":"Out-CompressedFile &#8226; The Lonely Administrator","og_description":"I'm not sure where this idea came from, but I thought it might be nice to redirect output to a compressed text file. I know disk space is cheap these days but perhaps you're running PowerShell 2.0 on an older platform and you want to save output from a command that will generate a ton...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/","og_site_name":"The Lonely Administrator","article_published_time":"2010-12-06T16:50:08+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-1024x619.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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Out-CompressedFile","datePublished":"2010-12-06T16:50:08+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/"},"wordCount":746,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-1024x619.png","keywords":["functions","Out-File","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/","name":"Out-CompressedFile &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile-1024x619.png","datePublished":"2010-12-06T16:50:08+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/12\/out-compressedfile.png","width":"1129","height":"683"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1025\/out-compressedfile\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Out-CompressedFile"}]},{"@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":8693,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8693\/exporting-powershell-functions-to-files\/","url_meta":{"origin":1025,"position":0},"title":"Exporting PowerShell Functions to Files","author":"Jeffery Hicks","date":"December 3, 2021","format":false,"excerpt":"When I write a PowerShell module, it typically includes more than one export function. Where you store your module functions is a great discussion topic and I don't think there is necessarily one best practice for everyone. I think it might depend on the number and complexity of the functions.\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\/12\/export-function3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":703,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","url_meta":{"origin":1025,"position":1},"title":"Export-Function","author":"Jeffery Hicks","date":"July 19, 2010","format":false,"excerpt":"I love that you can do so much with PowerShell on the fly.\u00a0 For example, I don\u2019t need to launch a script editor to create a PowerShell function. I can do it right from the command prompt. PS C:\\> function tm {(get-date).ToLongTimeString()} PS C:\\> tm 12:41:27 PM As long as\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":445,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/445\/more-fun-with-get-numberedcontent\/","url_meta":{"origin":1025,"position":2},"title":"More Fun with Get-NumberedContent","author":"Jeffery Hicks","date":"October 13, 2009","format":false,"excerpt":"As much fun as the original Get-NumberedContent function was after using it for awhile I realized I had imposed some limitations. I also realized it needed to be more flexible. What if someone wanted to specify a different color or use a different comment character such as a ; in\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"Help Get-NumberedContent","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/captured_Image2.png_thumb2.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":356,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/356\/out-msword-revised\/","url_meta":{"origin":1025,"position":3},"title":"Out-MSWord Revised","author":"Jeffery Hicks","date":"September 18, 2009","format":false,"excerpt":"This summer I wrote about a function I developed called Out-MSWord. The function was discussed in my Practical PowerShell column which was published in the free e-Journal Windows Administration in RealTime put out by RealTime Publishers. The original was published in Issue #17 if you are interested. The function accepted\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"help-out-msword","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/helpoutmsword_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":8709,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8709\/converting-powershell-scripts-to-functions\/","url_meta":{"origin":1025,"position":4},"title":"Converting PowerShell Scripts to Functions","author":"Jeffery Hicks","date":"December 10, 2021","format":false,"excerpt":"Recently, I shared some PowerShell code to export a function to a file. It was a popular post. My friend Richard Hicks (no relation) thought we was joking when he asked about converting files to functions. His thought was to take a bunch of PowerShell scripts, turn them into a\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\/12\/poc-modulecommands.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/poc-modulecommands.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/poc-modulecommands.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/poc-modulecommands.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2613,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2613\/create-powershell-scripts-with-a-single-command\/","url_meta":{"origin":1025,"position":5},"title":"Create PowerShell Scripts with a Single Command","author":"Jeffery Hicks","date":"December 5, 2012","format":false,"excerpt":"One of the drawbacks to using a PowerShell script or function is that you have to write it. For many IT Pros, especially those new to PowerShell, it can be difficult to know where to start. I think more people would write their own tools if there was an easy\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\/2011\/10\/talkbubble-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1025","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=1025"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1025\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}