New DSCCheckSum - PowerShell


Overview

New-DSCCheckSum generates a checksum of a file or directory for use in a Desired State Configuration (DSC) configuration. It ensures the integrity of files and directories during deployment and enables accurate verification of the desired state.

Syntax

New-DSCCheckSum [-Path] <string> [-Algorithm <string>] [-Verbose] [-Confirm] [-WhatIf] [-Force]

Options/Flags

  • -Path: Path to the file or directory for which the checksum is generated. Required.
  • -Algorithm: Algorithm to use for checksum generation. Supports MD5, SHA1, SHA256, SHA384, and SHA512. Default: SHA256.
  • -Verbose: Enable verbose logging.
  • -Confirm: Prompt for confirmation before executing the command.
  • -WhatIf: Display what the command would do without executing it.
  • -Force: Overwrite existing checksum file.

Examples

Example 1: Generate a SHA256 checksum of a file

New-DSCCheckSum -Path "C:\Scripts\Install-Software.ps1"

Example 2: Generate a MD5 checksum of a directory

New-DSCCheckSum -Path "C:\Program Files\Microsoft\Office" -Algorithm MD5

Common Issues

  • Invalid Path: Ensure the specified path is valid and accessible.
  • Unsupported Algorithm: The specified checksum algorithm must be supported by the PowerShell platform.
  • File Not Found: If the file being checksummed does not exist, an error will be displayed.

Integration

New-DSCCheckSum can be integrated with other PowerShell commands for advanced tasks:

  • Compare Checksums: Use Compare-Object to compare checksums for different files or directories.
  • Integrate into DSC Scripts: Use the checksums generated by New-DSCCheckSum in DSC configuration blocks to verify resource integrity.