This topic is a how to.
Please keep it as clear and simple as possible. Avoid speculative discussions as well as deep dive into underlying mechanisms or related technologies.

You might want to insert formatted and colored code syntax (the colorized and formatted script code is easier to read on Web pages and stands out a lot more). This will help readers understand the syntax faster when they read it.

Inserting code into the Wiki-editor can be a little tricky if you want Windows PowerShell code syntax formatting. This article assumes that you are using Windows PowerShell ISE (that is a part of PowerShell V2) or PowerGUI Script Editor from Quest Software.

Using PowerShell ISE

  1. Click here to go to the PowerShellPack Web site (opens in a new window). Download and install PowerShellPack.
  2. Run the Windows PowerShell ISE editor.
  3. In Windows PowerShell ISE command prompt type the following command: Import-Module PowerShellPack.
  4. In the menu bar will appear new element named Add-Ons.
  5. In the Windows PowerShell ISE editor, open the already saved Windows PowerShell script or just type your code manually.
  6. Select a code part that you want to insert into the Wiki editor.
  7. In Add-Ons menu click IsePack, click Edit and then click Copy-ColoredAsHTML.
  8. Now the selected code is saved to clipboard into HTML format.
  9. Return back to the Wiki editor.
  10. Click the HTML button in the toolbar and paste the HTML code into the window in the appropriate location.
  11. Paste HTML code from clipboard to editor.
  12. It is a good idea to use good fonts for pasting source code in the editor. Therefore change leading <pre> tag to the following:

    <pre style="font-family: consolas; font-size: 12px" class="PowerShellColorizedScript">

  13. The result should be something like this:
#####################################################################            
# Test-Me.ps1            
# Version 0.63            
#            
# This script just tests something            
#            
#####################################################################            
#requires -Version 2.0            
            
function Test-Me {            
[CmdletBinding()]            
 param (            
  [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]            
  [string]$Argument            
 )            
 Write-Host "You have passed the following argument to me:"            
 Write-Host $Argument            
}

 

Using PowerGUI

  1. Click here to go to website http://software.dell.com/products/powergui-freeware (opens in a new window). Download and install PowerGUI Script Editor
  2. Run PowerGUI Script Editor
  3. In PowerGUI Script Editor open already saved Windows PowerShell script or just type your code manually.
  4. Select code part which you want to insert into the Wiki editor
  5. In Edit menu click Copy As and click HTML
  6. Now selected code is saved to clipboard into HTML format
  7. Return back to the Wiki editor
  8. Click the HTML button in the toolbar and paste the HTML code into the window in the appropriate location
  9. Paste HTML code from clipboard to editor
  10. It is a good idea to use good fonts for pasting source code in the editor. Therefore change leading <pre> tag to the following:

    <pre style="font-family: consolas; font-size: 12px">

  11. The result should be something like this:
#####################################################################
# Test-Me.ps1
# Version 0.63
#
# This script just tests something
#
#####################################################################
#requires -Version 2.0

function Test-Me {
[CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
        [string]$Argument
    )
    Write-Host "You have passed the following argument to me:"
    Write-Host $Argument
}


See Also


 

Other Languages

This article is also available in other languages: