Your question is not very clear. Thus, you may have to adjust the function a bit. By the way, if you are trying to deploy a website, copying a directory is not the best way.
function Copy-Directory { param ( [parameter(Mandatory = $true)] [string] $source, [parameter(Mandatory = $true)] [string] $destination ) try { Get-ChildItem -Path $source -Recurse -Force | Where-Object { $_.psIsContainer } | ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } | ForEach-Object { $null = New-Item -ItemType Container -Path $_ } Get-ChildItem -Path $source -Recurse -Force | Where-Object { -not $_.psIsContainer } | Copy-Item -Force -Destination { $_.FullName -replace [regex]::Escape($source), $destination } } catch { Write-Error "$($MyInvocation.InvocationName): $_" } } $releaseDirectory = $BuildFilePath + $ProjectName + "\" + $ProjectName + "\bin\" + $compileMode + "_PublishedWebsites\" + $ProjectName $sitePath = "\\$strSvr\c$\Shared\WebSites" Copy-Directory $releaseDirectory $sitePath
source share