{"id":1180,"date":"2011-03-03T10:16:06","date_gmt":"2011-03-03T15:16:06","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1180"},"modified":"2013-10-30T20:22:49","modified_gmt":"2013-10-31T00:22:49","slug":"powershell-automatic-logging","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/","title":{"rendered":"PowerShell Automatic Logging"},"content":{"rendered":"<p>If you regularly download or look at the functions and scripts I post here, you'll notice I often use Write-Verbose to indicate what is happening. This comes in handy for troubleshooting. But often it would also be helpful to record as a log file of script activity. Unfortunately, you can't pipe Write-Verbose to Out-File. So I came up with my own function called Write-Log that gives me the best of both worlds. I can get verbose messages and send those messages to a text file for logging.<\/p>\n<p>The function is relatively simple. This is the core code without the comment based help.<\/p>\n<pre class=\"lang:ps decode:true \" >Function Write-Log {\r\n    [cmdletbinding()]\r\n\r\n    Param(\r\n    [Parameter(Position=0)]\r\n    [ValidateNotNullOrEmpty()]\r\n    [string]$Message,\r\n    [Parameter(Position=1)]\r\n    [string]$Path=\"$env:temp\\PowerShellLog.txt\"\r\n    )\r\n    \r\n    #Pass on the message to Write-Verbose if -Verbose was detected\r\n    Write-Verbose $Message\r\n    \r\n    #only write to the log file if the $LoggingPreference variable is set to Continue\r\n    if ($LoggingPreference -eq \"Continue\")\r\n    {\r\n    \r\n        #if a $loggingFilePreference variable is found in the scope\r\n        #hierarchy then use that value for the file, otherwise use the default\r\n        #$path\r\n        if ($loggingFilePreference)\r\n        {\r\n            $LogFile=$loggingFilePreference\r\n        }\r\n        else\r\n        {\r\n            $LogFile=$Path\r\n        }\r\n        \r\n        Write-Output \"$(Get-Date) $Message\" | Out-File -FilePath $LogFile -Append\r\n    }\r\n\r\n} #end function\r\n<\/pre>\n<p>The function takes two parameters, -Message and -Path. The former is the string of text you want to display and\/or log to a text file. The Path is the filename and path of the log file. I've given this parameter a default value of $env:temp\\PowerShellLog.txt. The function writes the message string to the log file with the current date and time prepended.<\/p>\n<pre class=\"lang:ps decode:true \" >Write-Output \"$(Get-Date) $Message\" | Out-File -FilePath $LogFile -Append<\/pre>\n<p>Output is always appended to the log file. Because the function uses cmdlet binding, if it detects -Verbose then the Write-Verbose message will be visible.<\/p>\n<pre class=\"lang:ps decode:true \" >#Pass on the message to Write-Verbose if -Verbose was detected\r\nWrite-Verbose -Message $Message\r\n<\/pre>\n<p>Now here's the fun part. I wanted to make Write-Log to behave like Write-Verbose. That is, I wanted to include the command in my scripts and functions but only have it actually do something when I needed it.  My Write-Log function looks for two variables. The first is $LoggingPreference. If this has a value of \"Continue\", then logging takes place. I also reference another variable called $loggingFilePreference. This variable contains the filename and path for your log file and takes precedence over the temp file default.<\/p>\n<pre class=\"lang:ps decode:true \" > #only write to the log file if the $LoggingPreference variable is set to Continue\r\n    if ($LoggingPreference -eq \"Continue\")\r\n    {\r\n    \r\n        #if a $loggingFilePreference variable is found in the scope\r\n        #hierarchy then use that value for the file, otherwise use the default\r\n        #$path\r\n        if ($loggingFilePreference)\r\n        {\r\n            $LogFile=$loggingFilePreference\r\n        }\r\n        else\r\n        {\r\n            $LogFile=$Path\r\n        }\r\n        \r\n        Write-Output \"$(Get-Date) $Message\" | Out-File -FilePath $LogFile -Append\r\n    }\r\n<\/pre>\n<p>There are several ways then that you could use this. First off, you need to dot source the function either in your PowerShell session or your script\/function.  Within your code use Write-Log just like you would Write-Verbose. To \"activate\", all you need to do is set $LoggingPreference to \"Continue\" somewhere. Here's one example.<\/p>\n<pre class=\"lang:ps decode:true \" >Function TryMe {\r\n    [cmdletbinding()]\r\n    Param([string]$computername=$env:computername,\r\n    [string]$Log\r\n    )\r\n    if ($log) \r\n    {\r\n     $loggingPreference=\"Continue\"\r\n     $loggingFilePreference=$log\r\n    }\r\n    Write-log \"Starting Command\"\r\n    Write-log \"Connecting to $computername\"\r\n    $b= get-wmiobject -class win32_bios -ComputerName $computername\r\n    $b\r\n    Write-log $b.version\r\n    Write-Log \"finished\" $log\r\n}\r\n\r\nPS C:\\&gt; TryMe -log e:\\logs\\sample.txt -verbose\r\n<\/pre>\n<p>My TryMe function includes a parameter called -Log. If I use this parameter, then the logging variables are set and my Write-Log commands will work. If I don't use -Log, Write-Log is still called but nothing is written.  Because TryMe uses cmdlet binding, if I run it with -Verbose then I'll get the verbose message via Write-Log. You can even use both -Verbose and -Log which will give you verbose messages and write to the log file. <\/p>\n<p>Another way would be to turn on the logging variable and use the default log. Here's a snippet.<\/p>\n<pre class=\"lang:ps decode:true \" >Function Test-Foo {\r\n\r\n[cmdletBinding()]\r\n\r\nParam([string]$name,\r\n [switch]$Logging\r\n)\r\n\r\nif ($Logging)\r\n{\r\n   $loggingPreference=\"Continue\"\r\n}\r\n\r\nWrite-Log \"Starting Test-Foo\"\r\n...\r\n}\r\n<\/pre>\n<p>This gives me the -Logging parameter that turns everything on. Remember, in this snippet the log file will the default in the TEMP folder. Although as an added bonus because you can specify a log file, you can write to multiple log files within the same script or function.<\/p>\n<p>I hope you'll let me know what you think and if you find this useful. If so, don't forget my tip jar.<\/p>\n<p>Download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/03\/Write-Log.txt' target=\"_blank\">Write-Log.ps1<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you regularly download or look at the functions and scripts I post here, you&#8217;ll notice I often use Write-Verbose to indicate what is happening. This comes in handy for troubleshooting. But often it would also be helpful to record as a log file of script activity. Unfortunately, you can&#8217;t pipe Write-Verbose to Out-File. So&#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,331,534,540,187],"class_list":["post-1180","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-functions","tag-logging","tag-powershell","tag-scripting","tag-write-verbose"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Automatic Logging &#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\/1180\/powershell-automatic-logging\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Automatic Logging &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"If you regularly download or look at the functions and scripts I post here, you&#039;ll notice I often use Write-Verbose to indicate what is happening. This comes in handy for troubleshooting. But often it would also be helpful to record as a log file of script activity. Unfortunately, you can&#039;t pipe Write-Verbose to Out-File. So...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-03-03T15:16:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-10-31T00:22:49+00:00\" \/>\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\\\/1180\\\/powershell-automatic-logging\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"PowerShell Automatic Logging\",\"datePublished\":\"2011-03-03T15:16:06+00:00\",\"dateModified\":\"2013-10-31T00:22:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/\"},\"wordCount\":515,\"commentCount\":17,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"functions\",\"logging\",\"PowerShell\",\"Scripting\",\"Write-Verbose\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/\",\"name\":\"PowerShell Automatic Logging &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2011-03-03T15:16:06+00:00\",\"dateModified\":\"2013-10-31T00:22:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/1180\\\/powershell-automatic-logging\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Automatic Logging\"}]},{\"@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 Automatic Logging &#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\/1180\/powershell-automatic-logging\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Automatic Logging &#8226; The Lonely Administrator","og_description":"If you regularly download or look at the functions and scripts I post here, you'll notice I often use Write-Verbose to indicate what is happening. This comes in handy for troubleshooting. But often it would also be helpful to record as a log file of script activity. Unfortunately, you can't pipe Write-Verbose to Out-File. So...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-03-03T15:16:06+00:00","article_modified_time":"2013-10-31T00:22:49+00:00","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\/1180\/powershell-automatic-logging\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"PowerShell Automatic Logging","datePublished":"2011-03-03T15:16:06+00:00","dateModified":"2013-10-31T00:22:49+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/"},"wordCount":515,"commentCount":17,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["functions","logging","PowerShell","Scripting","Write-Verbose"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/","name":"PowerShell Automatic Logging &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2011-03-03T15:16:06+00:00","dateModified":"2013-10-31T00:22:49+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1180\/powershell-automatic-logging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"PowerShell Automatic Logging"}]},{"@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":703,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","url_meta":{"origin":1180,"position":0},"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":8693,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8693\/exporting-powershell-functions-to-files\/","url_meta":{"origin":1180,"position":1},"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":7921,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7921\/answering-the-powershell-linking-challenge\/","url_meta":{"origin":1180,"position":2},"title":"Answering the PowerShell Linking Challenge","author":"Jeffery Hicks","date":"December 2, 2020","format":false,"excerpt":"A few weeks ago, the Iron Scripter challenge was to move files meeting some criteria to a new location and leave a link behind. As I've written before, these challenges are a great way to test your PowerShell skills and stretch yourself. This challenge has a number of moving parts.\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\/12\/new-item-link.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/new-item-link.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/new-item-link.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/new-item-link.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/new-item-link.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/new-item-link.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8709,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8709\/converting-powershell-scripts-to-functions\/","url_meta":{"origin":1180,"position":3},"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":8526,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8526\/doing-more-with-myinvocation\/","url_meta":{"origin":1180,"position":4},"title":"Doing More with $MyInvocation","author":"Jeffery Hicks","date":"August 19, 2021","format":false,"excerpt":"Not that long ago someone made a comment to me on Twitter about something I had shared related to PowerShell. He wanted to know more about the $MyInvocation variable. This is something that isn't well documented, yet can be very useful in your PowerShell scripting. Let's take a look at\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\/08\/myinvocation-debug-vscode.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/myinvocation-debug-vscode.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/myinvocation-debug-vscode.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/08\/myinvocation-debug-vscode.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":933,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/933\/powershell-ise-new-function\/","url_meta":{"origin":1180,"position":5},"title":"PowerShell ISE New Function","author":"Jeffery Hicks","date":"September 16, 2010","format":false,"excerpt":"Yesterday I showed how to add a menu choice to the PowerShell ISE to insert the current date and time. Today I have something even better. At least it's something I've needed for awhile. I write a lot of advanced functions in PowerShell. I'm often cutting and pasting from previous\u2026","rel":"","context":"In &quot;PowerShell ISE&quot;","block_context":{"text":"PowerShell ISE","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-ise\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/09\/ise-addons.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1180","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=1180"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1180\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}