Powershell - Create a folder from a file name in a CSV file, then move that file into that desination
I have 6000 PST files that need to be moved from a source location to a server share. Where my PowerShell is good enough to achieve this, if I had to move all the files in a given location, its not strong enough to figure out a way to do this when the PST files requiring the move are only 6000 out of 20000 in a complex folder structure.
I have a CSV file containing all the file paths of the PST files needing to be moved, and a single location to move them to, and again I would be able to script this, however, the requirement for my client is that the destination folder needs to be the name of the file that's moving.
I would like to be able to leverage PowerShell to query my CSV file with the 6000 files listed within it (using a column header or not, which ever is easier), have it create a new folder per file, and move the file from the source location specified in the CSV to the central Server Share.
So far I have come up with the following code, but it can only manage to do all items in a given location.
Get-ChildItem -File | # Get files Group-Object { $_.Name -replace '_.*' } | # Group by part before first underscore ForEach-Object { # Create directory $dir = New-Item -ItemType directory -Path \\Server\Share\ -Name $_.Name # Move files there $_.Group | Move-Item -Destination $dir }
Create a CSV with two columns and name them Source and Destination, I have tested this, but before you run it on 6000+ users please run a test yourself on a single account..
If successful you can then run on your organization ..
Open in new window
Create a CSV with two columns and name them Source and Destination, I have tested this, but before you run it on 6000+ users please run a test yourself on a single account..
If successful you can then run on your organization ..