.agents/skills/powershell/SKILL.md
Verb-Noun Format:
Parameter Names:
Variable Names:
Alias Avoidance:
function Get-UserProfile {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Username,
[Parameter()]
[ValidateSet('Basic', 'Detailed')]
[string]$ProfileType = 'Basic'
)
process {
# Logic here
}
}
Standard Parameters:
Path, Name, Force)Parameter Names:
Type Selection:
Switch Parameters:
function Set-ResourceConfiguration {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Name,
[Parameter()]
[ValidateSet('Dev', 'Test', 'Prod')]
[string]$Environment = 'Dev',
[Parameter()]
[switch]$Force,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string[]]$Tags
)
process {
# Logic here
}
}
Pipeline Input:
ValueFromPipeline for direct object inputValueFromPipelineByPropertyName for property mappingOutput Objects:
Pipeline Streaming:
PassThru Pattern:
-PassThru switch for object return-PassThrufunction Update-ResourceStatus {
[CmdletBinding()]
param(
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string]$Name,
[Parameter(Mandatory)]
[ValidateSet('Active', 'Inactive', 'Maintenance')]
[string]$Status,
[Parameter()]
[switch]$PassThru
)
begin {
Write-Verbose "Starting resource status update process"
$timestamp = Get-Date
}
process {
# Process each resource individually
Write-Verbose "Processing resource: $Name"
$resource = [PSCustomObject]@{
Name = $Name
Status = $Status
LastUpdated = $timestamp
UpdatedBy = $env:USERNAME
}
# Only output if PassThru is specified
if ($PassThru) {
Write-Output $resource
}
}
end {
Write-Verbose "Resource status update process completed"
}
}
ShouldProcess Implementation:
[CmdletBinding(SupportsShouldProcess = $true)]ConfirmImpact level$PSCmdlet.ShouldProcess() for system changesShouldContinue() for additional confirmationsMessage Streams:
Write-Verbose for operational details with -VerboseWrite-Warning for warning conditionsWrite-Error for recoverable errors that allow execution to continuethrow for fatal errors that stop executionWrite-Host except for user interface textError Handling Pattern:
Non-Interactive Design:
Read-Host in scriptsfunction Remove-UserAccount {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[string]$Username,
[Parameter()]
[switch]$Force
)
begin {
Write-Verbose "Starting user account removal process"
$ErrorActionPreference = 'Stop'
}
process {
try {
# Validation
if (-not (Test-UserExists -Username $Username)) {
Write-Error "User account '$Username' not found"
return
}
# Confirmation
$shouldProcessMessage = "Remove user account '$Username'"
if ($Force -or $PSCmdlet.ShouldProcess($Username, $shouldProcessMessage)) {
Write-Verbose "Removing user account: $Username"
# Main operation
Remove-ADUser -Identity $Username -ErrorAction Stop
Write-Warning "User account '$Username' has been removed"
}
}
catch [Microsoft.ActiveDirectory.Management.ADException] {
Write-Error "Active Directory error: $_"
throw
}
catch {
Write-Error "Unexpected error removing user account: $_"
throw
}
}
end {
Write-Verbose "User account removal process completed"
}
}
Comment-Based Docs: Include comment-based documentation for any public-facing function or cmdlet. Inside the function,
add a <# ... #> block with at least:
.SYNOPSIS Brief description.DESCRIPTION Detailed explanation.EXAMPLE sections with practical usage.PARAMETER descriptions.OUTPUTS Type of output returned.NOTES Additional informationConsistent Formatting:
Pipeline Support:
Avoid Aliases: Use full cmdlet names and parameters
Where-Object instead of ? or whereForEach-Object instead of %Get-ChildItem instead of ls or dirfunction New-Resource {
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
param(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string]$Name,
[Parameter()]
[ValidateSet('Development', 'Production')]
[string]$Environment = 'Development'
)
begin {
Write-Verbose "Starting resource creation process"
}
process {
try {
if ($PSCmdlet.ShouldProcess($Name, "Create new resource")) {
# Resource creation logic here
Write-Output ([PSCustomObject]@{
Name = $Name
Environment = $Environment
Created = Get-Date
})
}
}
catch {
Write-Error "Failed to create resource: $_"
}
}
end {
Write-Verbose "Completed resource creation process"
}
}