API Reference
Convert-ProjectConsistency
Converts a project to a consistent encoding/line ending policy and reports the results.
Remarks
This cmdlet applies a consistency policy (encoding and/or line endings) across a project tree. It can also export a post-conversion report so you can validate what remains inconsistent. For build-time enforcement, use New-ConfigurationFileConsistency -AutoFix in the module build pipeline.
Examples
Convert a PowerShell project to UTF-8 BOM + CRLF
PS>
Convert-ProjectConsistency -Path 'C:\MyProject' -ProjectType PowerShell -CreateBackups
Ensures PowerShell-friendly encoding and line endings, creating backups before changes.
Convert line endings only for a cross-platform repo
PS>
Convert-ProjectConsistency -Path 'C:\MyProject' -FixLineEndings -RequiredLineEnding LF -ExcludeDirectories 'Build','Docs'
Normalizes line endings to LF and skips non-source folders.
Convert encoding only with per-extension overrides
PS>
Convert-ProjectConsistency -Path 'C:\MyProject' -FixEncoding -RequiredEncoding UTF8BOM -EncodingOverrides @{ '*.xml' = 'UTF8' } -ExportPath 'C:\Reports\consistency.csv'
Uses UTF-8 BOM by default but keeps XML files UTF-8 without BOM, and writes a report.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.
Syntax
Convert-ProjectConsistency [-BackupDirectory <String>] [-CreateBackups] [-CustomExtensions <String[]>] [-EncodingOverrides <IDictionary>] [-EnsureFinalNewline] [-ExcludeDirectories <String[]>] [-ExcludeFiles <String[]>] [-ExportPath <String>] [-FixEncoding] [-FixLineEndings] [-Force] [-LineEndingOverrides <IDictionary>] [-NoRollbackOnMismatch] [-OnlyMissingFinalNewline] [-OnlyMixedLineEndings] -Path <String> [-ProjectType <PowerShell|CSharp|Mixed|All|Custom>] [-RequiredEncoding <ASCII>] [-RequiredLineEnding <CRLF|LF>] [-ShowDetails] [-SourceEncoding <Ascii>] [<CommonParameters>]
#
All Parameter SetsParameters
- BackupDirectory String
- Backup root folder (mirrors the project structure).
- CreateBackups SwitchParameter
- Create backup files before modifying content.
- CustomExtensions String[]
- Custom file extensions to include when ProjectType is Custom (e.g., *.ps1, *.cs).
- EncodingOverrides IDictionary
- Per-path encoding overrides (hashtable of pattern => encoding).
- EnsureFinalNewline SwitchParameter
- Ensure a final newline exists after line ending conversion.
- ExcludeDirectories String[]
- Directory names to exclude from conversion (e.g., .git, bin, obj).
- ExcludeFiles String[]
- File patterns to exclude from conversion.
- ExportPath String
- Export the detailed report to a CSV file at the specified path.
- FixEncoding SwitchParameter
- Convert encoding inconsistencies.
- FixLineEndings SwitchParameter
- Convert line ending inconsistencies.
- Force SwitchParameter
- Force conversion even when the file already matches the target.
- LineEndingOverrides IDictionary
- Per-path line ending overrides (hashtable of pattern => line ending).
- NoRollbackOnMismatch SwitchParameter
- Do not rollback from backup if verification mismatch occurs during encoding conversion.
- OnlyMissingFinalNewline SwitchParameter
- Only fix files missing the final newline.
- OnlyMixedLineEndings SwitchParameter
- Only convert files that have mixed line endings.
- Path String
- Path to the project directory to convert.
- ProjectType String
- Type of project to analyze. Determines which file extensions are included.
- Possible values:
PowerShell,CSharp,Mixed,All,Custom - RequiredEncoding FileConsistencyEncoding
- Target encoding to enforce when fixing encoding consistency.
- Possible values:
ASCII,UTF8,UTF8BOM,Unicode,BigEndianUnicode,UTF7,UTF32 - RequiredLineEnding FileConsistencyLineEnding
- Target line ending style to enforce when fixing line endings.
- Possible values:
CRLF,LF - ShowDetails SwitchParameter
- Include detailed file-by-file analysis in the output.
- SourceEncoding TextEncodingKind
- Source encoding filter. When Any, any non-target encoding may be converted.
- Possible values:
Ascii,BigEndianUnicode,Unicode,UTF7,UTF8,UTF8BOM,UTF32,Default,OEM,Any
Outputs
System.Object