Hi all, been a while.
I’ve been writing a script, which imports a CSV containing usernames, file names, and some other info. It’s an export of some user data I ran using another powershell scriptlet. It has 3 headers: SamAccountName, ScriptFile and HomePath.
All I’m wanting to do is to create a script to enumerate the CSV, look at the ScriptFile column, and do some stuff with it. The stuff consists of building some full paths to actual data (taken from the ScriptFile column for each user account) using Join-Path, printing out the final vars to make sure they are correct, then passing the completed string through to robocopy for some file move action. What I get is a looping output of the CSV file and NOTHING else.
I thought this would be easy, and I swear to god I’ve done this before using this method, and this stuff changes each time they update powershell… This is what I have so far…
# Import Data
Import-Csv G:\Scripts\homedrvs\homedrvs.csv
foreach ($user in $file) {
# Set vars
$ScriptFile=$user.ScriptPath
$SYSVOL="\\server\e$\Windows\SYSVOL\domain\scripts"
$ScriptPath=Join-Path -Path $SYSVOL -ChildPath $ScriptFile
$DestParentPath="G:\Scripts\homedrvs"
$DestPath=Join-Path -Path $DestParentPath -ChildPath $ScriptFile
# Test vars
Write-Host "`nFile source: $ScriptPath"
Write-Host "`nDestination: $DestPath"
# Perform copy script
#robocopy $ScriptPath $DestPath /e /r:3 /w:1 /tee /np /log+:G:\scripts\homedrvs\copylog.txt
}
As stated, all this does is spam my shell window with the entire contents of the CSV, and then loops round again for EACH line contained within the CSV. It’s ignoring the actual script - my brain cant work out the logic on this one!!
Any help appreciated.
Edit: This is with the actual robocopy command hashed out (as you see in the script block), so all I want to do is make sure the variables are correct before un-hashing it ![]()