mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 15:19:58 -05:00
29 lines
875 B
PowerShell
29 lines
875 B
PowerShell
function Copy-ItemSecure()
|
|
{
|
|
param(
|
|
[string]$Path,
|
|
[string]$Destination,
|
|
[switch]$Recurse,
|
|
[switch]$Force
|
|
);
|
|
|
|
if ((Test-Path $Path) -eq $FALSE) {
|
|
return $FALSE;
|
|
}
|
|
|
|
try {
|
|
if ($Recurse -And $Force) {
|
|
Copy-Item -Path $Path -Destination $Destination -Recurse -Force;
|
|
} elseif ($Recurse -And -Not $Force) {
|
|
Copy-Item -Path $Path -Destination $Destination -Recurse;
|
|
} elseif (-Not $Recurse -And $Force) {
|
|
Copy-Item -Path $Path -Destination $Destination -Force;
|
|
} else {
|
|
Copy-Item -Path $Path -Destination $Destination;
|
|
}
|
|
return $TRUE;
|
|
} catch {
|
|
Write-Host ([string]::Format('Failed to copy items from path "{0}" to "{1}": {2}', $Path, $Destination, $_.Exception)) -ForegroundColor Red;
|
|
}
|
|
return $FALSE;
|
|
}
|