## if the local directory exists, remove it
if (Test-Path -Path $LOCALFOLDER) {
Print-Debug "Deleting local folder: $LOCALFOLDER"
Remove-Item -Path "$LOCALFOLDER\*" -Recurse -Force | Out-Null
Remove-Item -Path "$LOCALFOLDER" -Recurse -Force | Out-Null
# yes i know it's twice - it's on purpose
## create the directory to house the workspace
New-Item -Path $LOCALFOLDER -Type Directory | Out-Null
## try to find the workspace
$workspace = $vcServer.GetWorkspace($WORKSPACENAME, $env:USERNAME)
if ($workspace -ne $null) {
Print-Debug "Workspace found, deleting it now.."
$vcServer.DeleteWorkspace($WORKSPACENAME, $env:USERNAME) | Out-Null
Print-Debug "No workspace found."
## create the workspace, link to local directory
Print-Debug "Initializing workspace..."
$workspace = $vcServer.CreateWorkspace($WORKSPACENAME, $env:USERNAME)
$workspace.Map($SERVERPATH, $LOCALFOLDER)