Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!!

share|improve this question
can you show the error? – anacarolinats Mar 11 at 17:03
1  
sorry, didn't see your comment till now... thanks anyway! – trainee Mar 12 at 15:10

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
Thanks for the help, worked perfectly for me! – trainee Mar 12 at 13:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.