#This script file is used by teh vDiskReplicator script to perform an unbuffered copy using robocopy
#from a source PVS Server to a target PVS Server
#This script was created by Rob Zylowski Citrix CCS with help from many folks
#It should be used as an example of how to perform PVS Disk replication.
#
#Although every effort has been made to ensure that these sample scripts work properly, 
#Citrix disclaims any responsibility for any and all liability or responsibility for any 
#damages that may result from using these scripts. 
#The sample scripts are provided to you as is, with no warranty or guarantees.
#

#Version 2 2-27-2019
#Updated to handle allowing the remote folder location to be passed versus defined
#Version 4.0 5-18-2021 Modified to allow for PowerShell Remoting

Param($PVSServer,$StoreName,$LocalPath)

function Get-ScriptDirectory
{
  $Invocation = (Get-Variable MyInvocation -Scope 1).Value
  Split-Path $Invocation.MyCommand.Path
}

#$ScriptPath = Get-ScriptDirectory
$ScriptPath = $LocalPath

Function LogLine($strLine)
{
	Write-Host $strLine
	$global:StrTime = Get-Date -Format MM-dd-yyyy-HH-mm-tt
	$global:strFilesOutput += "$global:StrTime - $strLine `r`n" 
	"$global:StrTime - $strLine " | Out-file -FilePath $global:OutfileRunning -Encoding ASCII -Append
}


if (!(Test-Path "$ScriptPath\Logs")){mkdir "$ScriptPath\Logs"}

$LogName = "$StoreName-"+"$PVSServer"+"_Log.txt"
$global:OutfileRunning = "$LocalPath\Logs\$LogName"
if (!(Test-Path $LocalPath\Logs))
{
	mkdir "$LocalPath\Logs"
}
Logline ""  
Logline "======Log for RunRobocopy on PVS Server $PVSServer"
Logline "Passed Parameters [$PVSServer][$StoreName][$LocalPath]"
Logline "/job:$LocalPath\$StoreName-$PVSServer.rcj"
robocopy /JOB:"$LocalPath\$StoreName-$PVSServer.rcj"
$Errortxt = "Errors [" + $Error[0] + "]"
Logline $Errortxt


