{"id":703,"date":"2010-07-19T12:12:23","date_gmt":"2010-07-19T17:12:23","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/2010\/07\/export-function\/"},"modified":"2010-07-19T13:25:57","modified_gmt":"2010-07-19T18:25:57","slug":"export-function","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","title":{"rendered":"Export-Function"},"content":{"rendered":"<p>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.<\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff;\">PS C:\\&gt; function tm {(get-date).ToLongTimeString()}<br \/>\nPS C:\\&gt; tm<br \/>\n12:41:27 PM<\/span><\/p>\n<p>As long as my PowerShell session is open, I can use the tm function. I can create as many other functions on the fly as I wish.\u00a0 Most of the time when I do this, the function is a throw-away. But occasionally I create a function from the command prompt that I\u2019d like to keep.\u00a0 I can see that the function object has a definition:<\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff;\">PS C:\\&gt; dir function:tm <\/span><\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff;\">CommandType\u00a0\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Definition<br \/>\n-----------\u00a0\u00a0\u00a0\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ----------<br \/>\nFunction\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tm\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (get-date).ToLongTimeString()<\/span><\/p>\n<p>All I need is a way to grab the definition and write it to a file. I may even want to write several functions to a single file or append the function to an existing file. Thus was born my Export-Function function.<\/p>\n<div id=\"codeSnippetWrapper\" style=\"border: 1px solid silver; text-align: left; padding: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New',courier,monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text;\">\n<div id=\"codeSnippet\" style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Function Export-Function {<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">&lt;<span style=\"color: #008000;\">#<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Synopsis<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Export a PowerShell <span style=\"color: #0000ff;\">function<\/span> to a file.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Description<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Get a Windows PowerShell <span style=\"color: #0000ff;\">function<\/span> and export it to a file. You can export functions<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">individually, each to its own file, or you can export them to the same file using<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">-Append. By <span style=\"color: #0000ff;\">default<\/span> the filename will be a PowerShell <span style=\"color: #0000ff;\">script<\/span> file with the same<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">name as the <span style=\"color: #0000ff;\">function<\/span>, but you can specify an alternate name. See examples.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Parameter Name<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">The name of the <span style=\"color: #0000ff;\">function<\/span> to export.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Parameter Path<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">The folder <span style=\"color: #0000ff;\">for<\/span> the exported <span style=\"color: #0000ff;\">function<\/span>.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Parameter Filename<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">The filename <span style=\"color: #0000ff;\">for<\/span> the exported <span style=\"color: #0000ff;\">function<\/span>. The <span style=\"color: #0000ff;\">default<\/span> is the <span style=\"color: #0000ff;\">function<\/span> name.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Parameter Append<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Write each <span style=\"color: #0000ff;\">function<\/span> to the same file.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Example<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">PS C:\\&gt; Export-Function <span style=\"color: #006080;\">\"MyFunction\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">This will export the MyFunction <span style=\"color: #0000ff;\">function<\/span> to a <span style=\"color: #0000ff;\">script<\/span> file called MyFunction.ps1.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Example<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">PS C:\\&gt; dir <span style=\"color: #0000ff;\">function<\/span>:*ISE* | Export-Function -path c:\\export -filename ISEFunctions.psm1 -append<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Get all functions with ISE <span style=\"color: #0000ff;\">in<\/span> the name and export them to a module file C:\\export\\ISEFunctions.psm1<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Inputs<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Strings <span style=\"color: #0000ff;\">for<\/span> <span style=\"color: #0000ff;\">function<\/span> names<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Outputs<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">None<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Link<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">About_Functions<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Function (provider)<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">.Notes<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">VERSION: 1.0<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">This <span style=\"color: #0000ff;\">function<\/span> supports cmdlet binding so you can use -Verbose and -Whatif.<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\"><span style=\"color: #008000;\">#&gt;<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[cmdletbinding(SupportsShouldProcess=$True)]<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Param(<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$True,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">HelpMessage=<span style=\"color: #006080;\">\"Enter the name of a current function to export\"<\/span>)]<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[ValidateNotNullorEmpty()]<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[string]$name,<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[Parameter(Position=1,HelpMessage=<span style=\"color: #006080;\">\"Enter the folder to store the file.\"<\/span>)]<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[ValidateScript({Test-path $_})]<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[string]$path=<span style=\"color: #006080;\">\"C:\\scripts\"<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[Parameter(Position=2,<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">HelpMessage=<span style=\"color: #006080;\">\"Enter the name of the file to create. The default is the function name.\"<\/span>)]<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[ValidateNotNullorEmpty()]<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[string]$filename=<span style=\"color: #006080;\">\"$name.ps1\"<\/span>,<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">[<span style=\"color: #0000ff;\">switch<\/span>]$append<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">)<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">    Begin {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        Write-Verbose <span style=\"color: #006080;\">\"Starting $($myinvocation.mycommand)\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        <span style=\"color: #008000;\">#initialize a counter<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        $i=0<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">    }<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">    Process {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        <span style=\"color: #008000;\">#verify function exists<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        try {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            $myfunction=Get-Command -Name $name -ErrorAction <span style=\"color: #006080;\">\"Stop\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        catch {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            Write-Warning <span style=\"color: #006080;\">\"Failed to find function $name\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            Return<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        }<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        <span style=\"color: #008000;\">#function found so continue<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        <span style=\"color: #0000ff;\">if<\/span> ($myFunction) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            <span style=\"color: #008000;\">#increment the counter by 1<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            $i++<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            <span style=\"color: #008000;\">#strip out illegal filename characters from function name<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            [regex]$r=<span style=\"color: #006080;\">\"[:\/\\\\]\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            <span style=\"color: #0000ff;\">if<\/span> ($r.matches($filename)[0]) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                Write-Verbose <span style=\"color: #006080;\">\"Removing illegal filename characters from $filename\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                $r.matches($filename) | <span style=\"color: #0000ff;\">foreach<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                 $filename=$filename.replace($_.value,<span style=\"color: #006080;\">\"\"<\/span>)<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            } <span style=\"color: #008000;\">#if $r.matches<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            $filepath=Join-Path -Path $path -ChildPath $filename<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\"><span style=\"color: #008000;\">#this command needs to be left justifie so the final result is nicely<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\"><span style=\"color: #008000;\">#formatted<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">$output=@(<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\"><span style=\"color: #006080;\">\"{0} {1} {2} <\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\"> {3}<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">{4} #end function<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">###############################################################################<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">\" -f $myFunction.commandtype,$myFunction.name,<span style=\"color: #006080;\">\"{\"<\/span>,$myFunction.definition,<span style=\"color: #006080;\">\"}\"<\/span>)<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">          <span style=\"color: #0000ff;\">if<\/span> ($pscmdlet.ShouldProcess($name)) {<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            <span style=\"color: #0000ff;\">if<\/span> ($append) {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                write-Verbose <span style=\"color: #006080;\">\"Exporting and appending to $filepath\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            $output | Out-File -FilePath $filepath -Append<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            <span style=\"color: #0000ff;\">else<\/span> {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                Write-Verbose <span style=\"color: #006080;\">\"Exporting $name to $filepath\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">                $output | Out-File -FilePath $filepath<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">            }<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">           } <span style=\"color: #008000;\">#if shouldprocess<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        } <span style=\"color: #008000;\">#if $myFunction<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">    } <span style=\"color: #008000;\">#process<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">    End {<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        Write-Verbose <span style=\"color: #006080;\">\"Ending $($myinvocation.mycommand)\"<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">        Write-Host <span style=\"color: #006080;\">\"Exported $i functions\"<\/span> -ForegroundColor Green<\/pre>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">    }<\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">} <span style=\"color: #008000;\">#end function<\/span><\/pre>\n<p><!--CRLF--><\/p>\n<p><!--CRLF--><\/p>\n<pre style=\"border-style: none; text-align: left; padding: 0px; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New',courier,monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible;\">Set-Alias -Name ef -Value Export-Function<\/pre>\n<p><!--CRLF--><\/p>\n<\/div>\n<\/div>\n<p>This is an advanced PowerShell 2.0 function with complete help and examples. The script file that loads the function also defines an alias of <em>ef<\/em>.<\/p>\n<p>By default Export-Function takes a function and creates a ps1 file using the function name as the file name. For example, to export my tm function<\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff;\">PS C:\\&gt; export-function tm<\/span><\/p>\n<p>This will create a file called tm.ps1 in C:\\Scripts. The function has a \u2013Path parameter to specify the default folder. I\u2019ve given it a default value of C:\\scripts. You might want to change the default value.<\/p>\n<p>Because a function might have characters in the name like :, which don\u2019t make good file names, I use a regular expression object to strip them out of the filename. If you specify a filename, then the function names will be left alone. At the end of each function is a separator line of ######################################. This comes in handy when exporting a number of functions to the same file.<\/p>\n<p><span style=\"font-family: Consolas; color: #0000ff;\">PS C:\\&gt; dir function:*firefox*\u00a0 | export-function -path c:\\work -filename Firefox.psm1 \u2013append<\/span><\/p>\n<p>This will take all the functions in my current session with Firefox in the name and add them to a module file, c:\\work\\firefox.psm1. Very handy when you want to throw together a module. The function supports cmdlet binding so you can use \u2013Verbose and \u2013Whatif.<\/p>\n<p><span style=\"font-family: Consolas;\"><span style=\"color: #0000ff;\">PS C:\\&gt; dir function:out* | export-function -whatif -verbose<\/span><\/span><br \/>\n<span style=\"color: #000000;\">VERBOSE: Starting Export-Function<\/span><br \/>\n<span style=\"font-family: Consolas;\"> <\/span><span style=\"font-family: Consolas;\"><span style=\"color: #0000ff;\">What if: Performing operation \"Export-Function\" on Target \"Out-Notepad\".<\/span><\/span><br \/>\nWhat if: Performing operation \"Export-Function\" on Target \"Out-MSWord\".<br \/>\n<span style=\"font-family: Consolas;\"><span style=\"color: #0000ff;\">What if: Performing operation \"Export-Function\" on Target \"Out-Clip\". <\/span><\/span><br \/>\n<span style=\"font-family: Consolas;\"><span style=\"color: #0000ff;\"> <\/span><span style=\"color: #000000;\">VERBOSE: Ending Export-Function<\/span> <\/span><br \/>\n<span style=\"font-family: Consolas;\"><span style=\"color: #008000;\">Exported 0 functions<\/span><\/span><\/p>\n<p>As always, I hope you find this useful and will let me know what you think.<\/p>\n<div id=\"scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:18022628-b3b7-4b06-9f64-b5c92585d285\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; display: inline; float: none; padding: 0px;\">\n<div><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/07\/ExportFunction.txt\" target=\"_blank\">Download Export-Function.ps1<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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:\\&gt; function tm {(get-date).ToLongTimeString()} PS C:\\&gt; tm 12:41:27 PM As long as my PowerShell session is open,&#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":[75,8],"tags":[204,32,534,540],"class_list":["post-703","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","category-scripting","tag-export","tag-functions","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>Export-Function &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Export-Function &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"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:&gt; function tm {(get-date).ToLongTimeString()} PS C:&gt; tm 12:41:27 PM As long as my PowerShell session is open,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2010-07-19T17:12:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2010-07-19T18:25:57+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\\\/scripting\\\/703\\\/export-function\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Export-Function\",\"datePublished\":\"2010-07-19T17:12:23+00:00\",\"dateModified\":\"2010-07-19T18:25:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/\"},\"wordCount\":460,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"export\",\"functions\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/\",\"name\":\"Export-Function &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2010-07-19T17:12:23+00:00\",\"dateModified\":\"2010-07-19T18:25:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/703\\\/export-function\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell v2.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-v2-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Export-Function\"}]},{\"@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":"Export-Function &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","og_locale":"en_US","og_type":"article","og_title":"Export-Function &#8226; The Lonely Administrator","og_description":"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:&gt; function tm {(get-date).ToLongTimeString()} PS C:&gt; tm 12:41:27 PM As long as my PowerShell session is open,...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","og_site_name":"The Lonely Administrator","article_published_time":"2010-07-19T17:12:23+00:00","article_modified_time":"2010-07-19T18:25:57+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\/scripting\/703\/export-function\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Export-Function","datePublished":"2010-07-19T17:12:23+00:00","dateModified":"2010-07-19T18:25:57+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/"},"wordCount":460,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["export","functions","PowerShell","Scripting"],"articleSection":["PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/","name":"Export-Function &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2010-07-19T17:12:23+00:00","dateModified":"2010-07-19T18:25:57+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/703\/export-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell v2.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},{"@type":"ListItem","position":2,"name":"Export-Function"}]},{"@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":3918,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3918\/pimp-your-prompt\/","url_meta":{"origin":703,"position":0},"title":"Pimp your Prompt","author":"Jeffery Hicks","date":"July 16, 2014","format":false,"excerpt":"If you are like me and live in PowerShell, then you spend a great deal of your day looking at your PowerShell prompt. That little indicator in the console and ISE that usually shows where you are. That little part of your PowerShell world is defined by a built-in function\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":"bling2","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/bling2-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6240,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6240\/friday-fun-with-timely-powershell-prompts\/","url_meta":{"origin":703,"position":1},"title":"Friday Fun with Timely PowerShell Prompts","author":"Jeffery Hicks","date":"November 30, 2018","format":false,"excerpt":"If PowerShell is a part of your daily routine, you most likely have a console window open all day. In addition to using PowerShell to get stuff done, you can use PowerShell to keep you on track. I've written before and talked about how I use PowerShell to manage my\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/11\/image_thumb-13.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":959,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/959\/custom-prompts-3-ways\/","url_meta":{"origin":703,"position":2},"title":"Custom Prompts 3 Ways","author":"Jeffery Hicks","date":"October 12, 2010","format":false,"excerpt":"Recently, a number of PowerShell MVPs were having a discussion about the transcript feature in Windows PowerShell. One comment that arose was a need to see how long tasks have run or otherwise provide some sort of date time information. One solution is to use a customized PowerShell prompt and\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/10\/colorprompt-300x127.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4398,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4398\/friday-fun-i-can-run-that-command-in-3-letters\/","url_meta":{"origin":703,"position":3},"title":"Friday Fun: I Can Run that Command in 3 Letters","author":"Jeffery Hicks","date":"May 8, 2015","format":false,"excerpt":"If you have been using PowerShell for any length of time, I'm sure you are familiar with aliases. An alias is an alternative name to a PowerShell cmdlet. They are intended to serve as transition aids (like dir and ls) and as a means to keep interactive typing to a\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"Large Blog Image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/03\/faveicon-551a9375v1_site_icon-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":984,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/984\/export-registry\/","url_meta":{"origin":703,"position":4},"title":"Export Registry","author":"Jeffery Hicks","date":"October 18, 2010","format":false,"excerpt":"Over the last week or so I've posted some functions for testing whether a given registry item exists or not, or even validating its value. To round this out, today I have an advanced function that makes it easier to export parts of the registry on the local computer. The\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":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/10\/export-registry-help-1024x526.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/10\/export-registry-help-1024x526.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/10\/export-registry-help-1024x526.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1307,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1307\/friday-fun-powershell-pep-talk\/","url_meta":{"origin":703,"position":5},"title":"Friday Fun PowerShell Pep Talk","author":"Jeffery Hicks","date":"April 1, 2011","format":false,"excerpt":"Today's Friday Fun is meant to help get you excited about the upcoming Scripting Games. I want to add a little pep to your PowerShell prompt. Perhaps it will even keep you motivated. What I have for you today are variety of prompt functions. Consider them variations on a theme.\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"PowerShell Pep Talk","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/04\/color-pep-prompt-300x144.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/703","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=703"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/703\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}