Powershell
--
Questions
--
Followers
Top Experts
So i write a little powershell script
$Importcsv = "C:\csv\MoveHomerDir.csv"
$HomeDirList = Import-csv $Importcsv
Foreach($HomeFolder in $HomeDirList){
$NewDir = "Migrate_Directory"
$CurrentDirPath = $HomeFolder.NewHomeDir
$NewDirPath = "$CurrentDirPath\$NewDir"
#Verify if new subfolder allready exist
If (Test-Path -Path $NewDirPath){
 Write-host "Directory $NewDir allready exist in $CurrentDirPath" -ForegroundColor Yellow
 }
 Else {
 New-Item -Name $NewDir -Path $CurrentDirPath -ItemType Directory
 }
#Start copy Directory
Foreach ($HomeDir in $HomeDirList) {
$HomeDirSource = $HomeDir.OldHomeDir
$HomeDirDest  = $HomeDir.NewHomeDir
robocopy "$HomeDirSource" "$HomeDirDest\$NewDir" /MIR /COPY:DATOU /LOG+:C:\Logs\TestMigrateH
}
}
My script works but copy directory seems to repeat itself, i don't understand why.
Did i forget something


Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
i did not know that robocopy will create the target directory automatically.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Powershell
--
Questions
--
Followers
Top Experts
Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.