1

So I am pretty green at powershell, and I have looked around for similar issues but can't seem to find out what my issue is. My CSV has usernames from active directory in it, and would work if the @{user= } wasn't there. I was pleased with myself for getting this far, but it seems I can't quite push it over the finish line. Please help StackOverFlow users!

$csvFile = 'C:\scripts\HomeDirectory\CN\CN-homedirectory.csv'
$SrcHome = '\\ch-hz-usrhome1\e$\Home\'
$DstHome = '\\us-svr-bk2\d$\files\CN_Files\'

  Import-Csv $csvFile -Delimiter ";" | ForEach-Object {
   $srcDoc = "$("$SrcHome$_.User")"
   $dstDoc = "$("$DstHome$_.User\UsersHomeDrive")"

    RoboCopy $srcDoc $dstDoc /Z /SEC /MIR /COPY:DAT /r:10 /w:40 /log+:C:\scripts\HomeDirectory\CN\CN_UserData.log
  }

When I look at the log file, I see the following:

Source : \\ch-hz-usrhome1\e$\Home\@{User=xyu}.User\
Dest : \\us-svr-bk2\d$\files\CN_Files\@{User=xyu}.User\UsersHomeDrive\
TriskalJM
  • 2,393
  • 1
  • 19
  • 20
jodokast89
  • 55
  • 9

1 Answers1

1

If you want a property of an object to be expanded in a string, you need to use the subexpression operator $().

A better way to build paths is to use Join-Path:

$srcDoc = Join-Path $SrcHome $_.User
$dstDoc = Join-Path $DstHome (Join-Path $_.User "UsersHomeDrive")
sodawillow
  • 12,497
  • 4
  • 34
  • 44