CmdLets/Master/Copy-ItemWrapper.ps1
|
Function Copy-ItemWrapper { <# .SYNOPSIS A wrapper function for copying files and directories with automated placeholder resolution, directory creation, and network share connection handling. .DESCRIPTION The Copy-ItemWrapper function extends the standard Copy-Item cmdlet by first processing source and destination paths through variable placeholder expansion (using Convert-PlaceholderVariables). It checks if the destination exists and creates it using New-ItemWrapper if necessary, handles automatic connection to UNC network paths if the source is missing, and recursively copies the items with force. .PARAMETER Path The path to the file or directory to be copied. Supports bracketed variable placeholders (e.g., "[SourceDir]\file.txt"). .PARAMETER Destination The destination path where the file or directory should be copied. Supports bracketed variable placeholders. .EXAMPLE Copy-ItemWrapper -Path "[InstallDir]\app.exe" -Destination "C:\Tools" Description: Resolves placeholders in the source path, verifies or creates the destination directory, and copies the file recursively. .NOTES Prerequisites: - Depends on custom helper functions such as Convert-PlaceholderVariables, New-ItemWrapper, and Connect-LibraryApplicationShare being available in the current session. .LINK https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item #> [CmdletBinding()] Param( [Parameter(Mandatory=$True)][String]$Path, [Parameter(Mandatory=$True)][String]$Destination ) $Path = Convert-PlaceholderVariables -Value $Path $Destination = Convert-PlaceholderVariables -Value $Destination if (!(test-path $Destination)) { Write-Verbose "Creating: $Destination" New-ItemWrapper $Destination } If (!(Test-Path $Path) -and $Path -like "\\*"){ Connect-LibraryApplicationShare -Path $Path } Write-Host "Copying: $($Path)" Get-Item $Path | Copy-Item -Destination "$Destination" -Force -Recurse } |