1

I'm having problems with a script which should function as a Backup replacement. This is only a part of the hole thing, the other stuff works but is dependent on it.

$datum = get-date -uformat "%Y-%m-%d"
$backupsrv = "\\192.168.0.5\"
$logpath = "$backupsrv\logs\$datum"
$test1 = "d:\test1","$backupsrv\b2d\test1","Test1"
$test2 = "c:\test2","$backupsrv\b2d\test2","Test2"
$programs = ($test1,$test2)

if (!(test-path -path $logpath))
{new-item $logpath -type directory}

function backup{
    param
    (
        [Parameter(Position=0,Mandatory=$true)]
        [String] $Source,

        [Parameter(Position=1,Mandatory=$true)]
        [String] $Target,

        [Parameter(Position=2,Mandatory=$true)]
        [String] $Name
    )

    if (!(test-path -path $target))
    {new-item $target -type directory}

    $LogFile = "$logpath\$name.log"

    robocopy "$Source" "$Target" /e /mir /np /ns /z /r:3 /w:30 /xf thumbs.db >>$logfile
}
foreach ($program in $programs){
    backup $program}

I always get an error with the parameter processing.

Could anyone help me with this ? Thanks!!

2
  • can you show the error? Commented Mar 11, 2013 at 17:03
  • 1
    sorry, didn't see your comment till now... thanks anyway! Commented Mar 12, 2013 at 15:10

1 Answer 1

1

It thinks you are passing in a string[] (which you are actually) instead of three separate strings. This actually works:

foreach ($program in $programs){
    backup $program[0] $program[1] $program[2]
}

You could set your function up to accept a string array if you wanted to.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.