How can I create a symbolic link between a network drive and a non-network drive ? I was never able to get it to work within command.

Also is there a way to append a sub-folder to a symbolic link; the -Path flag of a symbolic link must be non-existent for a symbolic link to be created ?

What have you tried?

I only tried the New-Item along with symbolic with the -Path and -Target.

Most forums are designed to help, not do for. Usually there is some code that isn’t working, and we can try to help getting it to work.

[quote quote=216057]Most forums are designed to help, not do for. Usually there is some code that isn’t working, and we can try to help getting it to work.

[/quote]
I understand, I just want to know what is missing as to get network drives first of all to create a symbolic link ?

Well I honestly believe you haven’t spent much time on this and are just asking someone else to tell you the answer. Either way, I’ll share my knowledge in case it helps.

The biggest issue I see people run into, is the path (directory or file) already exists. The process you are trying to do is CREATE a symbolic link - meaning it can’t already be there. You can create a symlink on your local drive that points to a network share, including subdirectories. See my examples below.

Scenario 1: Create a symbolic directory link on workstation1 to network share \server2\share. This command would be run on workstation1

New-Item -ItemType SymbolicLink -path C:\Temp\Linktest -Target \\server2\share



This will create a symlink directory in C:\Temp that looks just like a normal folder to the user (outside the shortcut icon on the folder.) They can create folders/files in here, and those folders files are actually being created in \server2\share

Scenario 2: Create a symbolic directory link on workstation1 to network share \server2\share\folder\in\share. This command would be run on workstation1

New-Item -ItemType SymbolicLink -path C:\Temp\Linktest -Target \\server2\share\folder\in\share



This will do the same as scenario 1, but the files/folder created in c:\temp\linktest are actually being written to \server2\share\folder\in\share\

I hope this helps.

[quote quote=216066]Well I honestly believe you haven’t spent much time on this and are just asking someone else to tell you the answer. Either way, I’ll share my knowledge in case it helps.

The biggest issue I see people run into, is the path (directory or file) already exists. The process you are trying to do is CREATE a symbolic link – meaning it can’t already be there. You can create a symlink on your local drive that points to a network share, including subdirectories. See my examples below.

Scenario 1: Create a symbolic directory link on workstation1 to network share \server2\share. This command would be run on workstation1

PowerShell
3 lines
<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
3
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This will create a symlink directory in C:\Temp that looks just like a normal folder to the user (outside the shortcut icon on the folder.) They can create folders/files in here, and those folders files are actually being created in \\server2\share

Scenario 2: Create a symbolic directory link on workstation1 to network share \server2\share\folder\in\share. This command would be run on workstation1

PowerShell
3 lines
<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
3
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This will do the same as scenario 1, but the files/folder created in c:\temp\linktest are actually being written to \\server2\share\folder\in\share\

I hope this helps.

[/quote]
Once one has created a symbolic link, is it possible to append a sub-folder the folder which is the Link ?

I’m not sure I understand the question. In the examples above, if you go into the symbolic link and create a sub folder, it is created in the target. If you’re wanting something like c:\temp\testlink\folder - then I’d say no because c:\temp\testlink isn’t a directory itself, it is just a shortcut. You could create another link pointing at the same target, but that link would need to be contained in a directory.

What if you created the symbolic link, but now want to add a sub-folder can this be done or must I delete the old symbolic link and create it from scratch ?

You could create another link pointing at the same target, but that link would need to be contained in a directory.
?

I hope this helps you.

Thanks for the help

You are welcome. To clarify, if you create a folder in the symlink folder and navigate to it, it looks like it is that path. For example if you go to the testlink above, create a directory, navigate into that directory - it will show c:\temp\testlink\newfolder in the explorer address bar. In fact any folder in there whether created through the symlink or directly through the shared path, will look local when accessed through the symlink.

Interestingly when you target the symlink to make a new symlink - it creates it just fine.

New-Item -ItemType SymbolicLink -path C:\Temp\Linktest\Linktest1 -Target \\server2\share\folder\in\share



Of course it creates it in the actual target folder. I thought that was interesting. So I guess to correct my answer, yes you can add a subfolder - it will exist in the target folder. Regarding “appending” to the symlink, if you really need a directory before the symbolic link and it needs to actually be local, you’d need to delete the symlink so you could create a folder with the same name as previously stated. Unfortunately you can’t do New-Item -ItemType SymbolicLink -Path c:\temp\testlink1\testlink1 -Target \server\share\folder unless c:\temp\testlink1 already exists.

An update, I tried the code you posted in your recent reply, and PowerShell continuously give me an error for a network drive.

I set the -path flag to the folder which is the source and the -Target flag to the target directory which is on a NAS; in either case, nothing works ?

I dont see any mention of the -Force option to New-Item. Will that solve your problem?

Perhaps you can paste the code you tried so there is no assuming going on. The folder “source” as you call it, must not exist. The symbolic link creation process will make the link. Make sure you’re not pointing at a preexisting item.

In a directory I want a shortcut named “Symboliclink” - this item must not exist already.

$path = "c:\temp\symboliclink"$target = "\\server\share\folder"

get-childitem $path # error for item not found New-Item -ItemType SymbolicLink -path$path -Target $target Get-ChildItem$path # should list anything contained in the $target directory  The source must not exist, therefore this is what I did; $path = “H:\CloudSync” < Non-existent
$target = “\crex2cloud\bacupsync” New-Item -ItemType SymbolicLink -path$path -Target $target Powershell pauses then I get the error Cannot find path \crex2cloud\bacupsync because it does not exist; although it does exist ? Sure you didn’t misspell a word? $target = "\\crex2cloud\bacupsync" # Not bac K upsync?


If that’s spelled correct, what happens if you run this?

Push-Location "\\crex2cloud\bacupsync"


[quote quote=228004]Sure you didn’t misspell a word?

<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
\$target = "\\crex2cloud\bacupsync" # Not bac K upsync?
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
If that’s spelled correct, what happens if you run this?
<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
Push-Location "\\crex2cloud\bacupsync"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] Same error ?

If you can’t push-location into it, then that system doesn’t recognize the path. I’d recommend you confirm the spelling/path. You say the path is valid, but this PC doesn’t think so. If you can navigate to it in explorer, perhaps you should copy/paste the path into your command to ensure accuracy.

I tried copying and pasting the path. I tried the UNC path, as well as the assigned letter path which is T, in either case it doesn’t work. The path exists in Windows explorer, but Powershell cannot find the path ?