LTI/ZTI PowerShell: Comment Based Help

I recommend using PowerShell comment based help to document your deployment scripts as described on Technet in about_Comment_Based_Help. This makes your scripts self documenting so colleagues can see who wrote it, what it does and examples and parameter usage. Below, I’ve added an example of comment based help to my evolving rename-computer script.

Anything between the <# and #> in PowerShell is a comment. I’ve also documented it internally by adding a # comment line to each section of code.

<#

.SYNOPSIS

Lite-Touch Deployment script to rename a computer

 

.DESCRIPTION

The ZTIRename-Computer.ps1 script will rename a computer and join a new workgroup.

   

.PARAMETER Name

Specifies the new computername

 

.PARAMETER WorkgroupName

Specifies the new Workgroup name

 

.EXAMPLE

%SCRIPTROOT%\ZTIRename-Computer.ps1

Add this line to your add powershell task sequence to take values from the deployment

properties OSDComputername and Workgroup. Remember to add the task sequence step

Restart Computer immediately after this step.

 

.EXAMPLE

ZTIRename-Computer.ps1 -Name PC01 -Workgroup Continuum

This will rename the computer to PC01 and the workgroup to Continuum after a reboot.

 

.NOTES

Author: Andrew Barnes

Date: 14 September 2012

 

.LINK

Online version: https://scriptimus.wordpress.com          

#>

 

Param (

    [String]$Name=$TSEnv:OSDComputername,

    [String]$WorkGroupName=$TSEnv:JoinWorkgroup

)

 

Begin{}

Process{

    # Rename the Computer using WMI

    (Get-WmiObject win32_computersystem).rename($Name)

 

    # Add the computer to a new workgroup

    Add-Computer -WorkGroupName $WorkGroupName -WarningAction SilentlyContinue

}

End{}

From a console, other users of the script can use the Get-Help cmdlet to access the documentation.

Comment_Based_Help

Advertisements

About Andrew Barnes

A Scripting and Deployment Specialist.
This entry was posted in Deployment, MDT 2010, MDT 2012, PowerShell, SCCM, Scripting and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s