
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.