CSS-Exchange
Copilot instructions1.3k starsChanged 6 months agoMITView on GitHub
NEVER commit, push, or create PRs without explicit user instruction. NEVER auto-fix issues found during code review. Report findings only. NEVER present code as complete without running Invoke-CodeFormatterOnFiles and SpellCheck.ps1 first. ALWAYS report findings and wait for user decision before modifying the repository. ALWAYS commit only the specific files the user requests. No extra files. ALWAYS use named parameters instead of positional parameters. ALWAYS ensure .ps1 files have UTF-8 BOM encoding. When counting code patterns (function calls, occurrences), ALWAYS exclude…
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about microsoft/CSS-Exchange
- PowerShell/PSScriptAnalyzer“UseCorrectCasing gets NullReferenceException from CommandInfo.get_Parameters”GitHub · Aug 23, 2021 · 3 reactions
- A Hacker News story“Microsoft IOC Detection Tool for Exchange Server Vulnerabilities”Hacker News · Mar 6, 2021 · 2 points
- microsoft/ContributorLicenseAgreement“Bot not recognizing MSFT employees”GitHub · Jul 23, 2024
- wazuh/wazuh“Adding rules for Hafnium related MS Exchange vulnerabilities”GitHub · Apr 20, 2021
- wazuh/wazuh“Add new rules for Hafnium MS Exchange vulnerabilities ”GitHub · Apr 9, 2021
The biggest 5 of 7 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 7
Talked about on GitHub and Hacker News (7 times).
On GitHub · 6
- Aug 23, 2021UseCorrectCasing gets NullReferenceException from CommandInfo.get_Parameters — PowerShell/PSScriptAnalyzer3 reactions · 2 comments
- Jul 23, 2024Bot not recognizing MSFT employees — microsoft/ContributorLicenseAgreement0 reactions · 2 comments
- Apr 20, 2021Adding rules for Hafnium related MS Exchange vulnerabilities — wazuh/wazuh0 reactions
- Apr 9, 2021Add new rules for Hafnium MS Exchange vulnerabilities — wazuh/wazuh0 reactions
- Mar 15, 2021We need a module for MS Exchange CVE-2021-26855 — OWASP/Nettacker0 reactions · 2 comments
1 more on GitHub
- Mar 8, 2021Is this script working? — GossiTheDog/scanning0 reactions · 4 comments
On Hacker News · 1
- Mar 6, 2021Microsoft IOC Detection Tool for Exchange Server Vulnerabilities2 points · 1 comment
In this repositoryOne other file it gives its agents.
- dependency-analysisSkill
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
22 rules. About 0 are common, 10 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 5
NEVER commit, push, or create PRs without explicit user instruction.
- Very specific: line 6
NEVER auto-fix issues found during code review.
- Very specific: line 7
NEVER present code as complete without running Invoke-CodeFormatterOnFiles and SpellCheck.ps1 first.
- Distinctive: line 8
ALWAYS report findings and wait for user decision before modifying the repository.
- Distinctive: line 9
ALWAYS commit only the specific files the user requests.
- Distinctive: line 10
ALWAYS use named parameters instead of positional parameters.
- Distinctive: line 11
ALWAYS ensure .ps1 files have UTF-8 BOM encoding.
- Distinctive: line 12
When counting code patterns (function calls, occurrences), ALWAYS exclude comment lines from the count.
- Distinctive: line 16
All code must pass these checks before being presented as complete:
- Very specific: line 50
If you create .copilot/agents/code-review.md, it completely replaces .github/agents/code-review.agent.md — it does not merge.
- Very specific: line 59
Only: use .copilot/agents/ override when testing a full agent rewrite, and delete the override once the change is promoted
- Distinctive: line 73
Before writing tests, reviewing code, or making any changes to a script:
- Distinctive: line 75
Read the full script to understand its purpose, logic, functions, parameters, and dependencies.
- Very specific: line 76
Use .build/Build.ps1 to generate dependency XML files (dist/dependencyHashtable.xml and dist/dependentHashtable.xml).
- Distinctive: line 81
All commands require PowerShell 7+ and should be run from the repository root.
- Very specific: line 152
Release: Only the final single .ps1 files in dist/ are released
- Very specific: line 212
Use # for single-line comments
- Very specific: line 213
Use <# #> for block comments (especially for complex logic)
- Very specific: line 214
Use .SYNOPSIS, .DESCRIPTION, .PARAMETER, .EXAMPLE for function help
- Distinctive: line 215
Avoid over-commenting obvious code.
- Very specific: line 247
Use BeforeAll to set up the environment and dot-source the script
- Very specific: line 249
Use Mock for external cmdlets (e.g., Exchange cmdlets, Get-ExchangeCertificate)
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Copilot Instructions for CSS-Exchange
Behavioral Rules
NEVER commit, push, or create PRs without explicit user instruction.
NEVER auto-fix issues found during code review. Report findings only.
NEVER present code as complete without running Invoke-CodeFormatterOnFiles and SpellCheck.ps1 first.
ALWAYS report findings and wait for user decision before modifying the repository.
ALWAYS commit only the specific files the user requests. No extra files.
ALWAYS use named parameters instead of positional parameters.
ALWAYS ensure .ps1 files have UTF-8 BOM encoding.
When counting code patterns (function calls, occurrences), ALWAYS exclude comment lines from the count.
Code Quality Standards
All code must pass these checks before being presented as complete:
. .build/Invoke-CodeFormatterOnFiles.ps1
Invoke-CodeFormatterOnFiles -FilePaths @("<your changed files>") -Save # Formatting, BOM, PSScriptAnalyzer
.build/SpellCheck.ps1 # Spelling (use PascalCase/camelCase)Available Agents and Skills
Specialized agents are available in .github/agents/ for specific tasks:
- code-review — Runs the quality pipeline and analyzes code for issues. Reports findings only, cannot modify files. Use:
"Use the code-review agent to review this PR" - code-creator — Creates and modifies PowerShell scripts following repo standards. Validates with
Invoke-CodeFormatterOnFilesandSpellCheck.ps1. Use:"Use the code-creator agent to create a new function" - pester-test — Creates Pester tests following repo patterns and performance rules. Use:
"Use the pester-test agent to write tests for FunctionName"
Skills are available in .github/skills/ and are automatically loaded when relevant:
- dependency-analysis — Maps cascading impact of changes using build system XML. Auto-loads when working with shared functions or assessing change impact. Can also be invoked explicitly:
"Use the /dependency-analysis skill to analyze impact of changing FunctionName"
Personal Overrides
Developers can create personal agents, skills, and instructions that override or extend the repo-level defaults without affecting other contributors. These directories are gitignored:
| Directory | Purpose | Behavior |
.copilot/copilot-instructions.md | Personal instructions | Merges with repo instructions (additive — safe) |
.copilot/agents/ | Personal agent overrides | Replaces repo agent entirely (use with caution) |
.copilot/skills/ | Personal skills | Available only to you |
.claude/ | Claude Code personal configuration | — |
.agents/ | Alternative personal agents/skills location | — |
Important: Agent Overrides Replace, They Don't Merge
If you create .copilot/agents/code-review.md, it completely replaces .github/agents/code-review.agent.md — it does not merge. This means:
- You must maintain the full agent file, not just your changes
- You won't receive repo-level updates to that agent until you delete your override
- Stale overrides silently mask improvements made by other contributors
Recommended Workflow for Iterating on Rules
- Discover a needed change while working → store it as a Copilot memory
- Test additive changes via
.copilot/copilot-instructions.md(safe — merges with repo) - Only use
.copilot/agents/override when testing a full agent rewrite, and delete the override once the change is promoted - Batch validated changes into a single PR to
.github/periodically - Clean up any memories that were promoted to files
Repository Overview
CSS-Exchange is a multi-script repository where:
- Main scripts live in domain folders (Admin, Calendar, Databases, Diagnostics, Hybrid, M365, Outlook, etc.)
- Shared utilities are in the
Shared/folder and are dot-sourced into scripts - Scripts are built into single
.ps1files in thedist/folder via the build system - All scripts follow PowerShell best practices enforced by PSScriptAnalyzer and custom formatting tools
Before Any Work: Understanding Script Context
Before writing tests, reviewing code, or making any changes to a script:
- Read the full script to understand its purpose, logic, functions, parameters, and dependencies.
- Use
.build/Build.ps1to generate dependency XML files (dist/dependencyHashtable.xmlanddist/dependentHashtable.xml). These are the authoritative source for all script relationships. - Map the cascading impact: changes to Shared functions affect direct callers AND their callers. The dependency-analysis skill auto-loads when relevant, or use
.github/skills/dependency-analysis/Get-DependencyCascade.ps1directly.
Build, Test, and Code Quality Commands
All commands require PowerShell 7+ and should be run from the repository root.
Building
.build/Build.ps1- Combines multi-file scripts into single-file releases in the
dist/folder - Embeds dot-sourced scripts and file resources (e.g.,
.txt,.html) directly into the output - Generates version numbers based on the most recent commit date for each script
Code Formatting and Linting
For targeted formatting of specific files (preferred for agents):
. .build/Invoke-CodeFormatterOnFiles.ps1
Invoke-CodeFormatterOnFiles -FilePaths @("<files to check>") -SaveFor formatting all changed files on a branch:
.build/CodeFormatter.ps1 -Save -Branch main- Runs PSScriptAnalyzer rules from
PSScriptAnalyzerSettings.psd1 - Automatically applies formatting fixes (indentation, braces, whitespace)
- Adds UTF-8 BOM to
.ps1files, removes it from.mdfiles CodeFormatter.ps1wrapsInvoke-CodeFormatterOnFileswith automatic file discovery
Spell Checking
.build/SpellCheck.ps1- Uses
cspell(Node.js-based tool) - Dictionary is in
.build/cspell-words.txt - Most spelling issues are caught by using proper camelCase or PascalCase variable names
- Note:
.github/is excluded from spell checking via.build/cspell.json
Testing (Pester)
.build/Pester.ps1- Runs all Pester tests (
*.Tests.ps1) found recursively across the repository (excludes.github/) - Runs tests in parallel (auto-scales to CPU cores)
- To test only changed files:
.build/Pester.ps1 -Branch main - Tests use
BeforeAllto dot-source scripts and set up the environment
Running the Full Pipeline
.build/CodeFormatter.ps1 -Save -Branch main
.build/SpellCheck.ps1
.build/Pester.ps1 -Branch main
.build/Build.ps1Then verify the output scripts in the dist/ folder.
High-Level Architecture
Multi-File to Single-File Pattern
The build system allows scripts to be developed as multi-file projects but released as single files:
- Development: Scripts can dot-source other
.ps1files and reference resources like.txtfiles - Build: The build system detects dot-sourcing and file inclusions, embeds them, and outputs to
dist/ - Release: Only the final single
.ps1files indist/are released
Dot-Sourcing Convention
Scripts dot-source shared functions with $PSScriptRoot-relative paths:
. $PSScriptRoot\HelperScript.ps1
. $PSScriptRoot\..\..\Shared\GenericScriptStartLogging.ps1Why: Allows scripts to run and be debugged at development time without building, and ensures the build system can find and embed them.
Shared Functions in Shared/
Common utilities organized by domain:
- ActiveDirectoryFunctions: AD queries and user lookups
- AzureFunctions: Azure AD/Graph API calls
- CertificateFunctions: Certificate handling
- EMailFunctions: Email parsing and validation
- ExchangeSessionFunctions: PowerShell remoting to Exchange
- GraphApiFunctions: Microsoft Graph API wrappers
- ErrorMonitorFunctions: Error tracking and reporting
- LoggerFunctions: Logging and output formatting
- Out-Columns.ps1: Colorized table output with word-wrapping
- ScriptUpdateFunctions: Auto-update capability (see below)
Other shared utilities:
- Confirm-ExchangeShell.ps1: Validates Exchange PowerShell is available
- Get-ProcessedServerList.ps1: Parses and deduplicates server lists
- Invoke-CatchActionError.ps1: Standardized error handling
Auto-Update Pattern
Scripts can enable auto-update by dot-sourcing Test-ScriptVersion.ps1:
. $PSScriptRoot\..\..\Shared\ScriptUpdateFunctions\Test-ScriptVersion.ps1
if (Test-ScriptVersion -AutoUpdate) {
Write-Host "Script was updated. Please rerun the command."
return
}This checks GitHub releases and downloads the latest version if available.
Key Conventions
Parameter and Variable Naming
- PascalCase for parameters and public functions:
$Identity,$TargetMailbox - camelCase for internal/local variables:
$results,$processedItems - UPPER_CASE for constants:
$MAX_RETRY_COUNT,$DEFAULT_TIMEOUT
Why: Variables in PascalCase pass spell-checking; inconsistency fails the spell check.
Comments and Documentation
- Use
#for single-line comments - Use
<# #>for block comments (especially for complex logic) - Use
.SYNOPSIS,.DESCRIPTION,.PARAMETER,.EXAMPLEfor function help - Avoid over-commenting obvious code; focus on why not what
Testing Patterns
Tests follow a colocated pattern: *.Tests.ps1 files are placed in a Tests/ subfolder adjacent to the script being tested. Examples:
Shared/Tests/*.Tests.ps1- Tests for shared utilitiesSetup/Tests/*.Tests.ps1- Tests for Setup scriptsDiagnostics/HealthChecker/Tests/*.Tests.ps1- Tests for HealthCheckerAdmin/MonitorExchangeAuthCertificate/DataCollection/Tests/*.Tests.ps1- Tests colocated near the script
Basic test structure:
BeforeAll {
$Script:parentPath = (Split-Path -Parent $PSScriptRoot)
. $Script:parentPath\ScriptToTest.ps1
# Load helper functions if needed
. $PSScriptRoot\..\..\Shared\PesterLoadFunctions.NotPublished.ps1
}
Describe "ScriptName" {
It "should do something" {
$result = Function-Name -Param "value"
$result | Should -Be "expected"
}
}Key conventions:
- Use
BeforeAllto set up the environment and dot-source the script - Prefix script-scope variables with
$Script:to avoid conflicts - Use
Mockfor external cmdlets (e.g., Exchange cmdlets, Get-ExchangeCertificate) - Store mock data in XML files in a
Tests/Data/subfolder:Import-Clixml $Script:parentPath\Tests\Data\MockData.xml - For complex multi-script testing (e.g., HealthChecker), create helper functions in
NotPublished.ps1files (e.g.,HealthCheckerTests.ImportCode.NotPublished.ps1) - Load functions dynamically with
Get-PesterScriptContentandInvoke-Expressionwhen testing individual functions from large scripts
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

