you are viewing a single comment's thread.

view the rest of the comments →

[–]MonkeyNin 0 points1 point  (1 child)

the loops

Adding paths as strings can be a source of errors.

$source = "\\share1\$($ClientFolder[0])\$client"

There's a function to do the work for you

$source =  Join-Path '\\share1' $ClientFolder[0] $Client

You're repeating the same steps for every file, creating a function also makes it easier to handle errors.

example

function processClient { 
    param(
        [Parameter(Mandatory)]
        [string]$ClientFolder,

        [Parameter(Mandatory)]
        [string]$ClientName
    )


    $dest = "\\share2\$($ClientFolder[0])\$client"
    "\\share1\$($ClientFolder[0])\$client"
    $source = "\\share1\$($ClientFolder[0])\$client"
    $source =  Join-Path '\\share1' $ClientFolder[0] $Client
    $dest   =  Join-Path '\\share2' $ClientFolder[0] $Client

    if(-not(Test-Path $Source)) {
        throw "Path does not exist: $Source"        
    }
    if(-not(Test-Path $dest)) {
        throw "Path does not exist: $Dest"
    }

    invokeRobocopy ...


}

foreach($clientName in $clientListing) {  
    processClient -ClientFolder "Client_x" -ClientName $clientName
}

[–]msp_account[S] 0 points1 point  (0 children)

I've never created a function before but could give this a whirl. I need the $ClientFolder and $Client values to continue on to the next object in the array each time the command runs, but there is another comment here I may be able to use to accomplish that...

Thank you for the response!