[Solved]Powershell Script to HardLink Multiple files from Source to Target Folder

46 Views Asked by At

I am not able to understand if I need an Array, how to set it up in Powershell and if i need something like for and stuff, since I'm not a developer and never dived into it too deep. So what I want to achieve, is to create HardLinks from Files in a Source Folder, into a Targetfolder and have this as a powershell script later. Since I want to safe Diskspace, I would prefer to create a HardLink instead of Copy Paste and having the files eating Diskspace. As example: Sourcefolder has -N files All shall be read into the array(?) to automize the hardlink creation. I already tried the hardlink creation with the New-Item element like shown below, but I always get the error, that the path can't be found, despite the path exists...

I'm clueless and I hope someone can help me there.

$source = "C:\temp1"
$target = "C:\temp2"
$filename = "" #Array filled variable with content from $source folder

Array.....

New-Item -Type HardLink -Path "$source\$filename" -Value "$target\$filename #Tried it and ends with Errors in Path not found. Don't understand why

Tested on Win 10 Pro 22H2 if it is necessary

Tried to create the powershell command for the hardlink creation and failed.

I would also accept cmd commandlets, if that's easier to generate and understand.

0

There are 0 best solutions below