Public/Compare-Folder.ps1
Function Compare-Folder { <# .SYNOPSIS This is a basic overview of what the script is used for.. .DESCRIPTION Thid command compares folders .NOTES Name: Compare-Folder Author: Mark Evans DateCreated: 2021-02-19 .EXAMPLE Compare-Folder -Name "Joe Bloggs" .LINK #> [CmdletBinding()] param( #Specifies an array of folders used as a reference for comparison. [Parameter( Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0 )] [ValidateScript( { Test-Path $_ -PathType 'Container' })] [System.IO.DirectoryInfo[]] $ReferenceFolder, #Specifies the folder that is compared to the reference folders. [Parameter(Mandatory, Position = 1)] [ValidateScript( { Test-Path $_ -PathType 'Container' })] [System.IO.DirectoryInfo] $DifferenceFolder ) BEGIN { Write-Debug -Message "BEGIN $($MyInvocation.MyCommand) : Version $($MyInvocation.MyCommand.Version)" $DifferenceFiles = Get-ChildItem $DifferenceFolder -Recurse } PROCESS { Write-Debug -Message "PROCESS $($MyInvoication.MyCommand)" foreach ($instanceReferenceFolder in $ReferenceFolder) { $instanceReferenceFiles = Get-ChildItem $instanceReferenceFolder -Recurse if ($DifferenceFiles) { if ($instanceReferenceFiles){ Compare-Object -ReferenceObject $instanceReferenceFiles -DifferenceObject $DifferenceFiles -PassThru -IncludeEqual ` -Property { $_.Name }, { (Get-FileHash $_.FullName).Hash } } else { $DifferenceFiles | Add-Member -NotePropertyName 'SideIndicator' -NotePropertyValue '=>' -PassThru } } else { $instanceReferenceFiles | Add-Member -NotePropertyName 'SideIndicator' -NotePropertyValue '<=' -PassThru } } } END { Write-Debug -Message "END: $($MyInvoication.MyCommand)" } } if ((Get-PSCallStack | Measure-Object).Count -eq 1) { # Compare-Folder -Debug # Remove-Item Function:${1:Verb-Noun} } |