alpha

Sets PowerShell cmdlet and scripting rules for a coding assistant: naming, parameters, error handling and idiomatic, safe script structure based on Microsoft guidelines.
applyTo: '/*.ps1,/*.psm1'
description: 'PowerShell cmdlet and scripting best practices based on Microsoft guidelines'
This guide provides PowerShell-specific instructions to help GitHub Copilot generate idiomatic,
safe, and maintainable scripts. It aligns with Microsoft’s PowerShell cmdlet development guidelines.
Verb-Noun Format:
Parameter Names:
Variable Names:
Alias Avoidance:
Get-ChildItem instead of gci)function Get-UserProfile {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Username,
[Parameter()]
[ValidateSet('Basic', 'Detailed')]
[string]$ProfileType = 'Basic'
)
process {
$outputString = "Searching for: '$($Username)'"
Write-Verbose -Message $outputString
Write-Verbose -Message "Profile type: $ProfileType"
# Logic here
}
}
Standard Parameters:
Path, Name, Force)Parameter Names:
Type Selection:
Switch Parameters:
[switch] for boolean flags, never [bool][bool]$Parameter or assign default values$false when omitted.IsPresent$true/$false in parameter attributes (e.g., Mandatory = $true) is acceptablefunction Set-ResourceConfiguration {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Name,
[Parameter()]
[ValidateSet('Dev', 'Test', 'Prod')]
[string]$Environment = 'Dev',
# ✔️ CORRECT: Use `[switch]` with no default value
[Parameter()]
[switch]$Force,
# ❌ WRONG: Shows incorrect default assignment, however this is correct syntax (requires `[switch]` cast).
[Parameter()]
[switch]$Quiet = [switch]$true,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string[]]$Tags
)
process {
# Use .IsPresent to check switch state
if ($Quiet.IsPresent) {
Write-Verbose "Quiet mode enabled"
}
}
}
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.IsPresent) {
Write-Output $resource
}
}
end {
Write-Verbose 'Resource status update process completed'
}
}
ShouldProcess Implementation:
[CmdletBinding(SupportsShouldProcess = $true)]ConfirmImpact level$PSCmdlet.ShouldProcess() as close the the changes action$PSCmdlet.ShouldContinue() for additional confirmationsMessage Streams:
Write-Verbose for operational details with -VerboseWrite-Warning for warning conditionsWrite-Error for non-terminating errorsthrow for terminating errorsWrite-Host except for user interface textError Handling Pattern:
[CmdletBinding()], prefer $PSCmdlet.WriteError() over Write-Error[CmdletBinding()], prefer $PSCmdlet.ThrowTerminatingError() over throwNon-Interactive Design:
Read-Host in scriptsfunction Remove-CacheFiles {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
param(
[Parameter(Mandatory)]
[string]$Path
)
try {
$files = Get-ChildItem -Path $Path -Filter "*.cache" -ErrorAction Stop
# Demonstrates WhatIf support
if ($PSCmdlet.ShouldProcess($Path, 'Remove cache files')) {
$files | Remove-Item -Force -ErrorAction Stop
Write-Verbose "Removed $($files.Count) cache files from $Path"
}
} catch {
$errorRecord = [System.Management.Automation.ErrorRecord]::new(
$_.Exception,
'RemovalFailed',
[System.Management.Automation.ErrorCategory]::NotSpecified,
$Path
)
$PSCmdlet.WriteError($errorRecord)
}
}
Comment-Based Help: Include comment-based help for any public-facing function or cmdlet. Inside the function, add a <# ... #> help comment 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 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'
$currentErrorActionValue = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
}
process {
try {
# Validation
if (-not (Test-UserExists -Username $Username)) {
$errorRecord = [System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new("User account '$Username' not found"),
'UserNotFound',
[System.Management.Automation.ErrorCategory]::ObjectNotFound,
$Username
)
$PSCmdlet.WriteError($errorRecord)
return
}
# ShouldProcess enables -WhatIf and -Confirm support
if ($PSCmdlet.ShouldProcess($Username, "Remove user account")) {
# ShouldContinue provides an additional confirmation prompt for high-impact operations
# This prompt is bypassed when -Force is specified
if ($Force -or $PSCmdlet.ShouldContinue("Are you sure you want to remove '$Username'?", "Confirm Removal")) {
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] {
$errorRecord = [System.Management.Automation.ErrorRecord]::new(
$_.Exception,
'ActiveDirectoryError',
[System.Management.Automation.ErrorCategory]::NotSpecified,
$Username
)
$PSCmdlet.ThrowTerminatingError($errorRecord)
} catch {
$errorRecord = [System.Management.Automation.ErrorRecord]::new(
$_.Exception,
'UnexpectedError',
[System.Management.Automation.ErrorCategory]::NotSpecified,
$Username
)
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
end {
Write-Verbose 'User account removal process completed'
# Set ErrorActionPreference back to the value it had
$ErrorActionPreference = $currentErrorActionValue
}
}
© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com


Butterfly on Wheat at Golden Sunrise
Paints a classical oil painting of a butterfly resting on a golden wheat stalk in misty backlit sunrise light with dewdrop bokeh.
image-prompt, oil-painting, painting, classical-art, animals, flowers, landscape, golden-hour, bokeh, dramatic-lighting, soft-lighting, vertical-format, macro, dreamy, impressionism, fine-art, vibrant-colors, spring, for-artists, gpt-image, wallpaper, quick

Chibi character 16 frame dance reference sheet
Creates a square 4x4 sheet of sixteen consecutive dance keyframes of an uploaded character, following numbered choreography steps with identity locked and secondary motion on hair and cloth.
image-prompt, character-sheet, multi-panel, dance, chibi, reference-image, character-consistency, character-design, full-body, white-background, illustration, structured-output, square-format, negative-prompt, gpt-image, for-artists, for-designers, game-assets, long-form, advanced

Running Man Pulled Back by Semi Chibi Double
Makes a bright studio editorial photo of a running person from a reference photo, with a 3D semi-chibi double tugging their clothes back and realistic fabric tension.
image-prompt, gpt-image, reference-image, face-reference, negative-prompt, photorealistic, editorial, chibi, 3d-render, studio-lighting, white-background, fashion, portrait, full-body, motion-blur, whimsical, vertical-format, character-consistency, action-figure, fashion-shoot, pixar-style, soft-lighting, for-photographers, for-artists, humorous
Loading reviews…
Loading comments…