$checkpath = "${env:UserProfile}\Appdata\Roaming\app1"
If (Test-Path -Path \\Server1\Shared\Apps1 -pathtype Container) {
if (-not (Test-Path -LiteralPath $checkpath -pathtype Container)) {
copy-item -path \\server1\shared\apps1 -destination $checkpath -recurse -force -verbose
}
Else {
Write-Output "Destination folder already exists."
}
}
Else {
Write-Output "Path \\Server1\Shared\Apps1 does not exist or is inaccessible."
}
This should do what you want it to do
$checkpath = "${env:AppData}\apps1"
if (-not (Test-Path -LiteralPath $checkpath)) {
Copy-Item -Path \\server1\shared\apps1\*.* -Destination $checkpath -Recurse -Force -WhatIf
}
What if: Performing the operation "Copy Directory" ...This means that Copy-Item is in "pretend" mode. You need to remove the -WhatIf at the end of line 3 to run it for real.
And if you're unsure about cmdlets that actually change anything, you can usually use the -WhatIf switch to see what would happen.
So this here is in test mode and will not actually copy anything; remove the -WhatIf to run it for real.
Open in new window
Edit: Changed path to use %AppData%