Jump to content

Recommended Posts

Posted

Hi everyone,

 

I've been tasked with migrating file data from many servers to many other servers and have been given a powershelll script to use (as it can be code signed). The script basically inserts parameters into robocopy but I'm having trouble with the directories, they are listed in Powershell but when I look at the robocopy log the directories are changed to c: (source) and c: (destination), not sure what I'm missing!

 

Set-StrictMode -Version 2.0
$VerbosePreference = "SilentlyContinue" # Set to SilentlyContinue to surpress write-verbose messages
$smtp			= “mail server”
$to			= “email”
$from			= “email”
$ScriptName		= $MyInvocation.MyCommand.Name
$subject 		= “Subject”
$logtime		= Get-Date -Format "yyyyMMddhhmm"
$attachments	= “Logs” + $logtime + ".log"
$emailbody 		= "

$($scriptname)running from $($PSScriptRoot) by $($env:username) on $($env:computername) " + `
				"

Attached log file


" + `
				“Please view"
#
#	Directories to mirror
#
$directories	= @( 	
					(“\\server\share\source”,	"\\server\share\destination”), `
					("\\server2\share\source",	"\\server2\share\destination") `
					)
$logging		= "/LOG:" + $attachments
$notify			= 0
#
foreach($directory in $directories)
{
Write-Verbose "$($directory[0])"
Robocopy $directory[0] $directory[1] /MIR /R:2 /W:5 /COPYALL /DCOPY:T /ZB $logging `
	/XF "~$*" ".vss_command" "Thumbs.db" ".DS_Store" "DS_Store" "*.tmp" `
	/XD "$directory[0]\Experiential\.TemporaryItems""$directory[1]\.TemporaryItems" "$directory[1]\~snapshot"
If ( $LASTEXITCODE -gt 1 )
{
	$notify = 1
}
$logging	= "/LOG+:" + $attachments
}
If ( $notify )
{
Send-MailMessage -To $to -from $from -Subject $subject -Body $emailbody -bodyashtml -SmtpServer $smtp -Attachments $attachments
Write-verbose "Email sent"
}

Posted

From the looks of that script they are hard coded so you need to change \\server\share\destination and source. For each server you'd need to modify this and also the

 

$directory[0] $directory[1]
adding accordingly.

 

I'm a strong believer in putting descriptions in a script so it is know what each section is doing, it's my main gripe about most of the scripts found on the Internet :censored:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...